I am getting this error on my index.php page where i have also included the code
<?pho
require 'connect.php';
?>
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given
<?php
$sql = "SELECT * FROM 'menulinks'";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result)) {
echo '<li>', $row['linktitle'], '<li>';
}
?>
Here is my connect function
<?php
$con = mysql_connect('localhost', 'root', '') or die('Sorry, we could not connect');
mysql_select_db('philipsnewsite', $con) or die('Sorry, we could not connect');
?>
You have quoted your table name in single-quote characters, which MySQL interprets as a string literal. You should either use backticks, or no quote characters at all:
$sql = "SELECT * FROM `menulinks`";
This syntax error caused the mysql_query()
function to return false, which you can test as follows:
$result = mysql_query($sql) or die(mysql_error());
Also note, as documented in a big red box at the top of the manual page for mysql_query()
:
Suggested alternatives
Use of this extension is discouraged. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include: