neonio Posted July 18, 2010 Share Posted July 18, 2010 Hi, i just joined the forum. i'm having trouble with a php script, i hope you can help me, cause i've searched through google a lot and found nothing. this is the script: <?php $db = new mysqli('localhost', 'user', 'pass', 'database'); if (mysqli_connect_errno()) { echo 'Fail'; exit; } $query = "SELECT * FROM 'test'"; $result = $db->query($query); $num_results = $result->num_rows; echo "Number of entries: ".$num_results."<br />"; echo "<table border = '1'> \n"; for ($i=0; $i<$num_results; $i++) { $row=$result->fetch_assoc(); echo "<tr> \n"; echo "<td>".$row["column1"]." / ".$row["column2"]."</td> \n"; echo "<td>".$row["column3"]."</td>\n"; echo "<td>".$row["column4"]."</td>\n"; echo "</tr> \n"; } echo "</table> \n"; ?> it gives the following error: Notice: Trying to get property of non-object in C:\apache\htdocs\showbd.php on line 11 which is $num_results = $result->num_rows; i'm using PHP 5.3.2, Apache 2.2.15, Mysql 5.1.48 and windows xp sp3, also i've enabled php extensions mysql and mysqli. i really don't know what could be wrong. Link to comment https://forums.phpfreaks.com/topic/208075-notice-trying-to-get-property-of-non-object-on-localhost/ Share on other sites More sharing options...
DavidAM Posted July 18, 2010 Share Posted July 18, 2010 I don't actually use mysqli, but the error message says $result is not an object. Therefore, $db->query() failed. That generally means there is a syntax error in your SQL statement. $query = "SELECT * FROM 'test'"; the table name does not be surrounded by single-quotes. $query = "SELECT * FROM test"; should be correct. If you not "quotes" around a table (or column) name, use back-ticks: $query = "SELECT * FROM `test`"; Link to comment https://forums.phpfreaks.com/topic/208075-notice-trying-to-get-property-of-non-object-on-localhost/#findComment-1087674 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.