mysql_fetch_array($result)
Posted by: nutanlade (117.195.132.---)
Date: March 28, 2008 06:23PM

In my program i used the following code to connect to database and executed a query

$result = mysql_query("SELECT * FROM cinemahall"winking smiley;

while($row = mysql_fetch_array($result))



Here at the while loop it is giving a warning saying that

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Users\nutan\Documents\phpdesigner_output_tmp.php on line 12


where the 12th line is the while loop.So please someone help me to solve this problem.

Thanq

Options: ReplyQuote
Re: mysql_fetch_array($result)
Posted by: toivo (203.19.130.---)
Date: March 28, 2008 10:14PM

Hi,

You need to create a connection to the MySQL server and select the database which gives you a connection resource. Even though it is possible to call mysql_query without the connection variable, it is best to include that connection resource as a parameter to the mysql_query:

$result = mysql_query("SELECT * FROM cinemahall", $my_db_connection);

You should also include error handling in your code, at least the following:

$result = mysql_query("SELECT * FROM cinemahall", $my_db_connection) or die ("Could not execute query: <br>\n" . mysql_errno() . ": " . mysql_error() . "<br>\n"winking smiley;

Error handling should also be part of the functions mysql_connect() and mysql_select_db(). That is the only way to get to see the first error message.

Regards,

toivo
Sydney, Australia



Edited 1 time(s). Last edit at 03/28/2008 11:34PM by toivo.

Options: ReplyQuote


Sorry, only registered users may post in this forum.