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);
?>`
5
  • 1
    What's your question? And why aren't you checking for errors? Commented Dec 9, 2011 at 6:22
  • Hi newbie, this is obvious, the supplied argument is not a valid mysql result on that particular line. Commented Dec 9, 2011 at 6:30
  • 2
    @bdonlan he has no idea of that? like 99% of this site users? Commented Dec 9, 2011 at 6: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 Commented Dec 9, 2011 at 6: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. Commented Dec 9, 2011 at 6:53

3 Answers 3

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 ...

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

-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.

2 Comments

Your missing the query, cmon basic stuff, whats $sql? and notofied is spelt notified...
Thanks for the pointing that out. Here you can learn the right way. Also keep in mind that doing error_reporting(0) on a live server is a suicide.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.