0

Possible Duplicate:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result

mysql_fetch_array(): supplied argument is not a valid MySQL result resource `

mysql_select_db("test", $con);
$result = mysql_query("SELECT * FROM order");

echo "<table border='1' bgcolor='#99CCCC' >"
while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>". $row['orderid']."</td>";
  echo "<td>". $row['odate'] . "</td>";
  echo "<td>". $row['pdtdetail']."</td>";
  echo "<td>". $row['unitprice']."</td> ";
  echo "<td>".$row['quantity']."</td> ";
  echo "<td>".$row['netprice']."</td> ";
  echo "<td>".$row['status']."</td>";
  echo "</tr>";
  }
echo "</table>";
mysql_close($con);
?>`
Community
  • 1
  • 1
  • 1
    What's your question? And why aren't you checking for errors? – bdonlan Dec 09 '11 at 06:22
  • Hi newbie, this is obvious, the supplied argument is not a valid mysql result on that particular line. – ajreal Dec 09 '11 at 06:30
  • 2
    @bdonlan he has no idea of that? like 99% of this site users? – Your Common Sense Dec 09 '11 at 06:40
  • @ajreal, yes very true ,for your question valid argument in your case is your query that you are passing, which implies that your query has some issue – noobie-php Dec 09 '11 at 06:40
  • @noobie-php I not sure what you mean ...Is not just limited to syntax in SQL, it could be you did not established the database connection correctly, database refused to connect, database reaching max-connection ... blah blah. – ajreal Dec 09 '11 at 06:53

3 Answers3

1
SELECT * FROM order <-- this is a wrongful SQL

order is reserved word in mysql.
If you have a table named as order,
you should rename it asap

Or back-tick the table name during query like :-

 SELECT * FROM `order`

When you code a SQL, it is understood is your responsibility
to ensure that query is working ...

ajreal
  • 46,720
  • 11
  • 89
  • 119
1

"order" is reserved keyword in mysql, chang it with ord or any else...

Rajesh Meniya
  • 753
  • 1
  • 7
  • 17
-1

While running queries, you have to always check for errors.
Run ALL your queruies at least this way:

$query  = "SELECT * FROM order"
$result = mysql_query($query) or trigger_error(mysql_error()." in ".$query); 

So, you will be always notified of the cause.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345