Hi... Unexpected Getting This Error When I'm Running This Code On My FTP Server, But On My Local PC, It's Working Perfect :S Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /mypath/form.php on line 17 $localhost = "localhost"; $username = ""; $password = ""; $database = "mydb"; $conn = mysql_connect($localhost,$username,$password); if(!$conn){ print "Unable to Connect DB"; } if(!mysql_select_db($database, $conn)){ print "Unable to select DB"; } $Query = "Select * From Orders"; $Result = mysql_query($Query, $conn); $Row = mysql_fetch_array($Result); // ERROR Is HERE $Id = $Row["Id"]; Code (markup):
The code looks fine. The only problem I can think of is that mysql_query() is failing. Try adding a check statement to see if it errors out, or simply: $Result = mysql_query($Query, $conn) or die(mysql_error()); PHP: Also, make sure the database &/or table(s) exist in the connection your making.
I usually check to make sure it's a valid resource before i call fetch array because an empty result can also cause an error. if(is_resource($Result)) { $Row = mysql_fetch_array($Result); } else { print(mysql_num_rows($Result)); print(mysql_error()); }
looks good to me, maybe you don't have your db set up correctly, use the "or die()" statement and see what it outputs
see if this helps : $localhost = "localhost"; $username = ""; $password = ""; $database = "mydb"; mysql_connect($localhost, $username, $password) or die(mysql_error()); mysql_select_db($database) or die(mysql_error()); $query = "Select * From Orders"; $result = mysql_query($query); while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { printf("ID: %s", $row["id"]); //echo 'ID : ' . $row['id'] . '<br/>'; } PHP: