Jump to content

$result not working


kevinritt

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.