phpstuff Posted October 17, 2013 Share Posted October 17, 2013 Below is how the page appears - it is printing out the mysql info and I'm not sure why(mysqli Object)? Your Website catchy slogan... Home Page Register View Users Change Password Login Registered Usersmysqli Object( [affected_rows] => 0 [client_info] => 5.5.29 [client_version] => 50529 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 0 [host_info] => Localhost via UNIX socket [info] => [insert_id] => 0 [server_info] => 5.5.29 [server_version] => 50529 [stat] => Uptime: 1043 Threads: 1 Questions: 33 Slow queries: 0 Opens: 49 Flush tables: 1 Open tables: 42 Queries per second avg: 0.031 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 4 [warning_count] => 0) There are currently 29 registered users. Name Date Registered Ullman, Larry September 06, 2013 Isabella, Zoe September 06, 2013 Starr, Ringo September 06, 2013 Harrison, George September 06, 2013 McCartney, Paul September 06, 2013 Lennon, John September 06, 2013 Brautigan, Richard September 06, 2013 Banks, Russell September 06, 2013 Simpson, Homer September 06, 2013 Simpson, Marge September 06, 2013 Simpson, Bart September 06, 2013 Simpson, Lisa September 06, 2013 Simpson, Maggie September 06, 2013 Simpson, Abe September 06, 2013 Chabon, Michael September 06, 2013 Greene, Graham September 06, 2013 DeLillo, Don September 06, 2013 Jones, David September 06, 2013 Dolenz, Micky September 06, 2013 Nesmith, Mike September 06, 2013 Sedaris, David September 06, 2013 Hornby, Nick September 06, 2013 Bank, Melissa September 06, 2013 Morrison, Toni September 06, 2013 Franzen, Jonathan September 06, 2013 jones-berg, mike September 18, 2013 O'Toole, Peter September 19, 2013 Dooleyberg, Amber September 26, 2013 Jones, Mike October 14, 2013 Copyright © Plain and Simple 2007 | Designed by edg3.co.uk | Sponsored by Open Designs | Valid CSS & XHTML CODE: <?php # Script 16.3 - view_users(16.3).php // This script runs a query on the username database, and retrieves all the records from the users table // This is an OOP version of script 9.6 $page_title = 'View the current users'; include ('includes/header.html'); // Page header echo '<h1>Registered Users</h1>'; require ('../mysqli_oop_connect.php'); // Connect to the database (file is placed outside of web root directory) // Make the query (dr = date registered) $q = "SELECT CONCAT(last_name, ', ', first_name) AS name, DATE_FORMAT(registration_date, '%M %d, %Y') AS dr FROM users ORDER BY registration_date ASC"; $r = $mysqli->query($q); // Count the number of returned rows $num = $r->num_rows; if ($num > 0) { // If it ran OK meaning the query returned at least 1 record, display the record(s) // Print how many users there are: echo "<p>There are currently $num registered users.</p>\n<br />"; // Table header echo '<table align="center" cellspacing="3" cellpadding="3" width="75%"> <tr><td align="left"><b>Name</b></td><td align="left"><b>Date Registered</b></td></tr> '; // Fetch and print all the records while ($row = $r->fetch_object()) { echo '<tr><td align="left">' . $row->name . '</td><td align="left">' . $row->dr . '</td></tr> '; } echo '</table>'; // Close the table $r->free(); // Free up the memory resources (an optional step that is considered good form) unset($r); } else { // If it did not run OK echo '<p class="error">There are currently no registered users.</p>'; } // End of if ($r) IF // Close the database connection $mysqli->close(); unset($mysqli); include ('includes/footer.html'); ?> Link to comment Share on other sites More sharing options...
phpstuff Posted October 17, 2013 Author Share Posted October 17, 2013 Sorry.. I didn't finish the post title and I went back to update it and you can't update it so it is cut off.... The page is showing mysql info being printed out and I'm not sure why.. Link to comment Share on other sites More sharing options...
Edward Posted October 17, 2013 Share Posted October 17, 2013 Well you are looping through the object you have their and printing out each row of results, that's why... // Fetch and print all the records while ($row = $r->fetch_object()) { echo '<tr><td align="left">' . $row->name . '</td><td align="left">' . $row->dr . '</td></tr> '; } Link to comment Share on other sites More sharing options...
phpstuff Posted October 17, 2013 Author Share Posted October 17, 2013 Isn't that excerpt of code just printing the actual data to the table which is what its supposed to do? I believe its printing the NAME and DATE REGISTERED values to a table which is correct. If I'm incorrect, and the code you pasted above is responsible for the mysql printout, then what part of my code prints the NAME and DATE REGISTERED values data to the table? To be clear, this is the part that I believe should NOT be displayed: mysqli Object( [affected_rows] => 0 [client_info] => 5.5.29 [client_version] => 50529 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 0 [host_info] => Localhost via UNIX socket [info] => [insert_id] => 0 [server_info] => 5.5.29 [server_version] => 50529 [stat] => Uptime: 1043 Threads: 1 Questions: 33 Slow queries: 0 Opens: 49 Flush tables: 1 Open tables: 42 Queries per second avg: 0.031 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 4 [warning_count] => 0) Link to comment Share on other sites More sharing options...
Edward Posted October 17, 2013 Share Posted October 17, 2013 The NAME is printed out by $row->name and the DATE REGISTERED is printed out by $row->dr. http://php.net/manual/en/mysqli.query.php 1. $r = $mysqli->query($q); returns a mysql object to $r. 2. $num = $r->num_rows; the num_rows property in the mysql object $r returns the number of rows 3. while ($row = $r->fetch_object()) We then use the while loop to loop through each row of data obtaining $row->name and $row->dr (Name and Date Registered). Link to comment Share on other sites More sharing options...
phpstuff Posted October 17, 2013 Author Share Posted October 17, 2013 I understand that and agree that.... / Fetch and print all the records while ($row = $r->fetch_object()) { echo '<tr><td align="left">' . $row->name . '</td><td align="left">' . $row->dr . '</td></tr> '; } ....is responsible for actually printing the NAME and DATE REGISTERED values. What I don't understand is what's printing this: mysqli Object( [affected_rows] => 0 [client_info] => 5.5.29 [client_version] => 50529 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 0 [host_info] => Localhost via UNIX socket [info] => [insert_id] => 0 [server_info] => 5.5.29 [server_version] => 50529 [stat] => Uptime: 1043 Threads: 1 Questions: 33 Slow queries: 0 Opens: 49 Flush tables: 1 Open tables: 42 Queries per second avg: 0.031 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 4 [warning_count] => 0) Where is there any echoing of the above? I see "r" being assigned a value, and used in a while loop, but never printed. If I wanted to eliminate the above from being printed to the page, what's the solution? Link to comment Share on other sites More sharing options...
Edward Posted October 17, 2013 Share Posted October 17, 2013 I lost my Larry's PHP Object Orientated book in my house some where i will go to look for it now. I need to see what that script does mysqli_oop_connect.php. Link to comment Share on other sites More sharing options...
Edward Posted October 17, 2013 Share Posted October 17, 2013 Found the book and realize now its not that one but the normal PHP Dynamic websites book, okay i think that message is being printed because in the mysqli_oop_connect.php script contains the code if ($mysqli->connect_error) { echo $mysqli->connect_error; unset($mysqli); cont.... You could just comment out that line to test the difference if ($mysqli->connect_error) { // echo $mysqli->connect_error; unset($mysqli); cont.... Its says connect_error will return a null value of there was no error message. So it may not be this, i did check online and did not find any information on this problem, so i don't know myself if its not this, i never saw this come up on my scripts before. I checked phpinfo() also and did not see any thing related. Link to comment Share on other sites More sharing options...
Edward Posted October 17, 2013 Share Posted October 17, 2013 I think there is some kind of php error, can you try turning on PHP error handling and see if you get another message coming up. ini_set('display_errors',1); error_reporting(E_ALL); Link to comment Share on other sites More sharing options...
Edward Posted October 17, 2013 Share Posted October 17, 2013 I just used the same script to connect to one of my databases to test it and i didn't get that mysqli object displaying. I really have no idea why that is showing either, it must be a local problem. I see you are using MAMP 2.1.3, i am using MAMP PRO 2.1.4, why don't you try upgrading, i really can't think of anything else. Link to comment Share on other sites More sharing options...
phpstuff Posted October 17, 2013 Author Share Posted October 17, 2013 Ahh... Yes you are correct - the code is in the included script mysqli_oop_connect.php. That makes sense now... Here is the culprit: echo '<pre>' . print_r($mysqli, 1) . '</pre>'; It looks like it was legacy code from a previous version of the script. It was the last line of code in the script. Thanks for your help!! Link to comment Share on other sites More sharing options...
Edward Posted October 17, 2013 Share Posted October 17, 2013 So it was the mysqli_oop_connect.php script, awesome good you got it figured out. Link to comment Share on other sites More sharing options...
Recommended Posts