Get error while returning data from mysql

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ghjk
    Contributor
    • Jan 2008
    • 250

    #1

    Get error while returning data from mysql

    When I retriwe data from mysql I got an error saying "Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource in C:\Program Files\xampp\htd ocs\xxxr\xxx.ph p on line 34". Please help me.
    Code:
    $sql="SELECT VehicleMake,VehicleType FROM vehicles WHERE VehicleType=$type AND VehicleMake=$make";
    	echo $sql;
    	$result = mysql_query($sql);
    	while($row = mysql_fetch_array($result))
    	{
    	echo $row['VehicleMake'] . " " . $row['VehicleType'];
    	echo "<br />";
    	}
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    If the mysql_query call fails, it will return FALSE instead of a MySQL resource.
    Also, if the query doesn't return a result table (like with INSERT or UPDATE queries), the call will return TRUE, rather then a MySQL resource.

    The mysql_fetch_arr ay function only takes a MySQL resource object, so if you don't make sure the query result is a resource, you will get this warning.

    Typically, you do something like:
    [code=php]
    $result = mysql_query($sq l);
    if($result) {
    while($row = mysql_fetch_arr ay($result)) {
    // etc.
    }
    }[/code]
    Or just
    [code=php]
    $result = mysql_query($sq l) or die(mysql_error ());
    while($row = mysql_fetch_arr ay($result)) {
    // etc.
    }[/code]

    Comment

    Working...