Jump to content

[HELP]Warning:mysql_fetch_array(): supplied argument is not a valid MySQL result


alanlaw87

Recommended Posts

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>";

 

 

 

?>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.