kevinritt Posted August 20, 2009 Share Posted August 20, 2009 I cannot figure why this code will not work: <? require("connections/dbconn.php"); $sql = "SELECT name, url, title FROM nav"; $result = $conn -> query($sql) or die(mysqli_error()); if($result) { while($row = $result->fetch_object()) { echo "<li><a href='{$row->url}' title='{$row->title}'>{$row->name}</a></li>"; } } ?> I don't see an error so can I assume that the connection to the database is not being made? Here's the connection/dbconn.php file: <? $conn = new MySQLi("localhost", "root", "***", "suagustv") or die(mysqli_error()); ?> Can anyone direct me where I should be looking? This is what I see on the page: query($sql) or die(mysqli_error()); if($result) { while($row = $result->fetch_object()) { echo "{$row->name} "; } } ?> Link to comment https://forums.phpfreaks.com/topic/171229-result-not-working/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 20, 2009 Share Posted August 20, 2009 Use full opening php tags <?php in all your code. The short open tag <? is not always enabled and you won't always be on a server where you can turn it on. You will waste more time trying to use short open tags than the time you will save by not typing the extra three letters to make it <?php. Link to comment https://forums.phpfreaks.com/topic/171229-result-not-working/#findComment-902949 Share on other sites More sharing options...
kevinritt Posted August 20, 2009 Author Share Posted August 20, 2009 yes, dumb oversight. Now I get this error: Notice: Undefined variable: conn in C:\wamp\www\saugustv_test\index.php on line 22 Fatal error: Call to a member function query() on a non-object in C:\wamp\www\saugustv_test\index.php on line 22 Is there somewhere I can see/understand what these errors mean? Link to comment https://forums.phpfreaks.com/topic/171229-result-not-working/#findComment-902953 Share on other sites More sharing options...
PFMaBiSmAd Posted August 20, 2009 Share Posted August 20, 2009 You need to use full <?php tags in connection/dbconn.php. Use full opening php tags <?php in all your code. Link to comment https://forums.phpfreaks.com/topic/171229-result-not-working/#findComment-902958 Share on other sites More sharing options...
Cosizzle Posted August 20, 2009 Share Posted August 20, 2009 ha, only someone with a larry king avatar can quote themselves Link to comment https://forums.phpfreaks.com/topic/171229-result-not-working/#findComment-902960 Share on other sites More sharing options...
kevinritt Posted August 21, 2009 Author Share Posted August 21, 2009 alright, alright I get it -'Dumbass of the week award' Link to comment https://forums.phpfreaks.com/topic/171229-result-not-working/#findComment-902998 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.