I have written a code running which returns with an error "supplied argument is not a valid mysql result resource" for:
Can anyone help me out what is wrong here? Thank youCode:<?php while($row = mysql_fetch_array($result)) { ?>
I have written a code running which returns with an error "supplied argument is not a valid mysql result resource" for:
Can anyone help me out what is wrong here? Thank youCode:<?php while($row = mysql_fetch_array($result)) { ?>
Don't talk unless you can improve the silence.
Your SQL query is failing. Use the or die mysql_error();. This will display the problem.
Code:<? $sql = "SELECT * FROM `mytable` WHERE `id` = '1'"; db_connect();//connecting mysql db function i wrote $result = mysql_query($sql) or die(mysql_error()); while($row = mysql_fetch_array($result)){ // do some thing here } mysql_close(db_connect()); ?>
This error message indicates that an error occurred in the call to mysql_query, which is indicated by a return of FALSE. FALSE is not a valid resource identifier, and so you get the error shown. When mysql_query returns FALSE, you should echo the error message indicated by mysql_error() to find out what the real error was.
It is possible that the query failed, or that you failed to connect to the database server. Checking for these potential problems and gracefully handling them should be the way to go.
Incidentally, use mysql_num_rows() not mysql_numrows() as the latter is deprecated.
Using "values" as a table name could create problems since values is a mysql keyword. Try changing the table name and see if it starts working.
Bookmarks