alanlaw87 Posted October 5, 2010 Share Posted October 5, 2010 Hi, I am having problem with mysql and php.... when i test the database on my local host it didt produce any error but when i put it on my web host it gave me error messages... "Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource" Please help me as i am new to php. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" href="http://www.hingloong.com/pricesearch/style.css" /> <title>Price Search Query</title> </head> <body> <form method=GET action="search.php"> <div id=container> <select name=general> <option value = all>Select</option> <option value = laptop>Laptop</option> <option value = mobile>Mobile</option> <option value = games>Games</option> <option value = camera>Camera</option> </select> <label><b>Brand:</b></label> <input type=text name=brand> <label><b>Model:</b></label> <input type=text name=model> <input type=submit name=search value=Search> </form> <br><br> <input type=button name=gamelist value=View Games onclick="location.href='gamelist.php'"> <input type=button name=mobilelist value=View Mobile onclick="location.href='mobilelist.php'"> <input type=button name=cameralist value=View Cameras onclick="location.href='cameralist.php'"> <input type=button name=laptoplist value=View Laptops onclick="location.href='laptoplist.php'"> </div> </body> </html> <?php include ("connect.php"); $general = $_GET['general']; $brand = $_GET['brand']; $model = $_GET['model']; if($general == 'mobile') { echo "<br>"; echo "<h3>Mobile Phone Prices</h3>"; echo "<div id=container>"; echo "<table>"; echo "<tr>"; echo "<td class=head>Phone Brand</td>"; echo "<td class=head>Phone Model</td>"; echo "<td class=head>Phone Loan</td>"; echo "<td class=head>Phone Buy</td>"; echo "<td class=head>Phone Sell</td>"; echo "<td class=head>Phone Rrp</td>"; echo "</tr>"; $query = "select * from mobilephones where phone_brand LIKE ('$brand%') AND phone_model LIKE ('$model%') "; $temp = mysql_query($query) or die(mysql_error()); } while ($row = mysql_fetch_array($temp)) { echo "<tr>"; echo "<td>" .$row['phone_brand']. "</td>"; echo "<td>" .$row['phone_model']. "</td>"; echo "<td>" .$row['phone_loan']. "</td>"; echo "<td>" .$row['phone_buy']. "</td>"; echo "<td>" .$row['phone_sell']. "</td>"; echo "<td>" .$row['phone_rrp']. "</td>"; } echo "</table>"; echo "</div>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/215189-helpwarningmysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/ Share on other sites More sharing options...
Mancent Posted October 5, 2010 Share Posted October 5, 2010 check you mysql tables to see if the collation is all the same. check field by filed and set the collation to the exact same every where. Quote Link to comment https://forums.phpfreaks.com/topic/215189-helpwarningmysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1119203 Share on other sites More sharing options...
alanlaw87 Posted October 5, 2010 Author Share Posted October 5, 2010 i did check and they do match, so i am not sure what is wrong... Quote Link to comment https://forums.phpfreaks.com/topic/215189-helpwarningmysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1119204 Share on other sites More sharing options...
PFMaBiSmAd Posted October 5, 2010 Share Posted October 5, 2010 Your query is inside of the conditional logic - if($general == 'mobile'){ your query is in here} but you are attempting to fetch the results after and outside of that conditional logic. Your code will produce that error every time it is executed and $general is not equal to 'mobile'. You need to fix your logic so that you only fetch the results from the query when the query is executed. Quote Link to comment https://forums.phpfreaks.com/topic/215189-helpwarningmysql_fetch_array-supplied-argument-is-not-a-valid-mysql-result/#findComment-1119229 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.