0

I am having a problem with a page that i've been working on and i get that error. Can someone please help?

Thanks

<?php
include 'connect.php';
$desc1 = mysql_query("SELECT * FROM desc WHERE descnum='1'");
$desc2 = mysql_fetch_assoc($desc1);
?>
<link rel="stylesheet" type="text/css" href="style.css" />
<div id="bar" align="center">
<h3><a href="index.php"/>Home</a></h3>
</div>
<div id="desc">
<?php echo $desc2['description']; ?>
</div>
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

2 Answers2

1

You may be having a problem due to the table name desc, in sql/mysql desc is a sort operator meaning descending. It is a reserved keyword baically, so your sql statement may be invalid and therefore not returning a valid result.

TomC
  • 139
  • 2
  • 12
1

TomC hit the nail on the head. "desc" is not an ideal table name. This can be simply overcome by using backticks "`" to enclose all table name and column names:

$desc1 = mysql_query("SELECT * FROM `desc` WHERE `descnum`='1'");

Furthermore, you may wish to edit your query execution to include the mysql_error function to return the sql error back:

$desc1 = mysql_query("SELECT * FROM `desc` WHERE `descnum`='1'") or die(mysql_error());

A final note is that PHP discourages the mysql extension... Instead, use the MySQLi extension or prepared statements (http://php.net/manual/en/function.mysql-query.php)