Jump to content

Warning: mysql_fetch_array(): supplied ar.... yes an other one but please HELP


scaleautostyle

Recommended Posts

Hi evrybody... I'm stuck in the boose now.... it was working fine before someone do a change... now I try to locate the error but I'm unable to do it.

 

my knowledge in php/mysql is VERY low in other word doens'y know nothing at all.

 

heres the message I receive

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/scale24/public_html/search-keyword.php on line 112

 

 

you can go directly on the site

 

http://scale24-25.com/search-db-foreach.php?cat=

 

the error appear when the vehicule manufacturer model dropdown was add. this menu autofill when you select one of the Name Of vehicule manufacturer droplist.

 

if someone can help me it will be VERY APPRECIATE.

 

you can view the before change here http://scale24-25.com/francaissource/search-db-foreachfr.php

 

thanks in advance

 

sebastien

Link to comment
Share on other sites

If you search for that error message, you will find that it generally means that your query is failing due to an error of some kind. It can also mean that you used the wrong variable name in the mysql_fetch_array() statement or that you overwrote the variable that holds the result resource from the query.

 

If the problem is due to the query failing, you can troubleshoot why by echoing mysql_error(); on the next line after the line with the mysql_query() statement.

Link to comment
Share on other sites

thanks but like I said my knowledge are near nothing. and these files were modify by near 5 person so the result I lost the control... now I try to get it but if you can help me to get back on the track it will be VERY appreciate.

 

I can post here the 2 files that comunicate between.  if you can tell me what exactly to change..

 

thanks in advance

 

sebastien

Link to comment
Share on other sites

thanks ... so this is the code of the form

 

<?php
include_once("db_connection.php");
//////////////////////////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>(Type a title for your page here)</title>
<SCRIPT language=JavaScript>
function reload(form)
{
var val=form.cat.options[form.cat.options.selectedIndex].value;
self.location='search-db-foreach.php?cat=' + val ;
}

</script>
</head>

<body >
<img src="http://www.scale24-25.com/images/banners/banner.jpg" alt="banner" width="997" height="213" border="0" usemap="#Map" />
<map name="Map" id="Map">
<area shape="poly" coords="0,100,85,102,92,55,108,50,326,51,323,7,3,3" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" />
<area shape="poly" coords="672,57,891,53,887,4,995,4,985,108,673,102" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" />
<area shape="poly" coords="326,12,330,52,98,53,90,91,670,98,668,53,889,50,886,4" href="http://www.scale-auto-style.com" alt="" />
<area shape="rect" coords="0,132,997,212" href="index.html">
</map>
<?php



/*
If register_global is off in your server then after reloading of the page to get the value of cat from query string we have to take special care.



@$cat=$_GET['cat']; // Use this line or below line if register_global is off
if(strlen($cat) > 0 and !is_numeric($cat)){ // to check if $cat is numeric data or not. 
echo "Data Error";
exit;
}

*/
@$cat=$HTTP_GET_VARS['cat']; // Use this line or above line if register_global is off


if (isset($_POST['todo']) && $_POST['todo'] == "search") {    $todo=$_POST['todo'];

$manufacturer_reel=$_POST['manufacturer_reel'];

$query="select * from kit where  ";

@$manufacturer_reel=$_GET['manufacturer_reel']; // Use this line or below line if register_global is off
if(strlen($manufacturer_reel) > 0 and !is_numeric($manufacturer_reel)){ // to check if $cat is numeric data or not. 
echo "Data Error";
exit;
}
/*
////////// Including manufacturer_reel field search ////
if(strlen($manufacturer_reel) > 0 ){
$query.= " manufacturer_reel='$manufacturer_reel' and "; 
}  
//// End of class field search /////////// */

$query=substr($query,0,(strLen($query)-4));

echo $query;
echo "<br><br>";
$nt=mysql_query($query);
echo mysql_error();

// End if form submitted



}else{

echo "<form method=post action='search-keyword.php?go'><input type=hidden name=todo value=search>";
?>
<table width="960" border="0">
  
  <tr>
    <td width="355"></td>
    <td width="250"> </td>
    <td width="355"> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td rowspan="9"><div align="center">To help me filling the database download the instruction and master file <a href="base de donnee/master_database.xls"><img src="catalog/images/design_web/master-bouton-en.jpg" alt="bout" width="272" height="54" border="0"></a></div></td>
    <td align="center"><?php


///////// Getting the data from Mysql table for first list box//////////
$q=mysql_query("SELECT DISTINCT manufacturer_reel,manufacturer_reel_id FROM kit order by manufacturer_reel"); 
///////////// End of query for first list box//////////



//////////        Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Please Choose an Option</option>";
while($row = mysql_fetch_array($q)) { 
if($row['manufacturer_reel_id']==@$cat){echo "<option selected value='$row[manufacturer_reel_id]'>$row[manufacturer_reel]</option>"."<BR>";}
else{echo  "<option value='$row[manufacturer_reel_id]'>$row[manufacturer_reel]</option>";}
}
echo "</select>"; 



//////////////////  This will end the first drop down list ///////////


/* //  strat of drop down  ///       ORIGINAL DROP DOWN
$q=mysql_query("SELECT DISTINCT manufacturer_reel FROM kit ORDER BY manufacturer_reel");
echo '<select name="manufacturer_reel"><option value="reel manufacturer">Please Choose an Option</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['manufacturer_reel'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";
//  end of drop down  /// */
echo " <br> \n";
echo " <br> \n";
//  end of drop down  ///

?></td>
    <td><div align="left">Name Of vehicule manufacturer</div></td>
  </tr>
  <tr>
    <td align="center"> </td>
    <td> </td>
  </tr>
  <tr>
    <td><div align="center">
        <?php /////// for second drop down list we will check if manufacturer_reel is selected else we will display all the car_model///// 
if(isset($cat) and strlen($cat) > 0){
$q=mysql_query("SELECT DISTINCT car_model FROM kit where manufacturer_reel_id=$cat order by car_model"); 
}else{$q=mysql_query("SELECT DISTINCT car_model FROM kit order by car_model"); } 

////////// end of query for second car_model drop down list box ///////////////////////////


//////////        Starting of second drop downlist //////////
/* echo "<select name='subcat'><option value=''>Please Choose an Option</option>";
while($row = mysql_fetch_array($q)) { 
echo  "<option value='$row[car_model]'>$row[car_model]</option>";
}
echo "</select>";
//////////////////  This will end the second drop down list ///////////
?>

*/

echo '<select name="car_model"><option value="car_model">Please Choose an Option</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['car_model'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";

echo " <br> \n";
echo " <br> \n";

?>
      </div>
    <td> vehicule manufacturer model</td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td align="center"><?php 
//  strat of drop down  ///
$q=mysql_query("SELECT DISTINCT scale FROM kit ORDER BY scale");
echo '<select name="scale"><option value="scale">Please Choose an Option</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['scale'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";

echo " <br> \n";
echo " <br> \n";

?></td>
    <td><div align="left">Scale of model</div></td>
  </tr>
  <tr>
    <td> </td>
    <td><div align="right"></div></td>
  </tr>
  <tr>
    <td align="center"><?php
//  start of drop down  ///
$q=mysql_query("SELECT DISTINCT manufacturer_kit FROM kit ORDER BY manufacturer_kit");
echo '<select name="manufacturer_kit"><option value="kit manufacturer">Please Choose an Option</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['manufacturer_kit'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";

//  end of drop down  ///
echo " <br> \n";
echo " <br> \n";

?></td>
    <td><div align="left">Name Of kit manufacturer</div></td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td align="center"><?php
//  strat of drop down  ///
$q=mysql_query("SELECT DISTINCT year_prod_reel FROM kit ORDER BY year_prod_reel");
echo '<select name="year_prod_reel"><option value="vehicules year manufactured">Please Choose an Option</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['year_prod_reel'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";
//  end of drop down  ///
echo " <br> \n";
echo " <br> \n";

?></td>
    <td><div align="left">
      <p>Year of production of the vehicule</p>
      <p> </p>
    </div></td>
  </tr>
  <tr>
    <td> </td>
    <td align="center"> </td>
    <td> </td>
  </tr>
  </table>
  
<table width="960" border="0">
            <tr>
              <td><div align="center">
                <?php

echo "
<br><input type=submit value=Search name='name' action='search-keyword.php?go' >
</form>
";
}


?>
              </div></td>
            </tr>
          </table>          
   
      
      <table width="980" border="1">
  <tr>
    <td colspan="3" bgcolor="#EDEDED"><div align="center"><a href="http://www.modelencyclopedia.com/"><img src="catalog/images/banners/davidcuraencyclopedy.gif" alt="banner1" border="0" /></a></div></td>
  </tr>
  <tr>
    <td bgcolor="#EDEDED" width="480"><p align="center">Without his help this site will stay under development</p>    </td>
    <td> </td>
    <td bgcolor="#EDEDED" width="480"><p align="center">Sans son aide se site serais toujours en dévelopement</p>    </td>
  </tr>
</table>






</body>

</html>

 

this is the code of the file it will return the result.

 

<?php

include_once("db_connection.php");
//////////////////////////////
?>
<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>(Type a title for your page here)</title>

</head>

<body >
<p align="center"><img src="http://www.scale24-25.com/images/banners/banner.jpg" alt="banner" width="997" height="213" border="0" usemap="#Map" />
<map name="Map" id="Map">
<area shape="poly" coords="0,100,85,102,92,55,108,50,326,51,323,7,3,3" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" />
<area shape="poly" coords="672,57,891,53,887,4,995,4,985,108,673,102" href="http://www.hobby-shop.qc.ca" alt="hobby-shop" />
<area shape="poly" coords="326,12,330,52,98,53,90,91,670,98,668,53,889,50,886,4" href="http://www.scale-auto-style.com" alt="" />
<area shape="rect" coords="0,132,997,212" href="index.html">
</map></p>
<table width="920" border="0">
  <tr>
    <td width="359"><p class="style5">You will find some TBC. TBC is for "To Be Confirmed". If somebody know the missing information ( TBC ) it will be appreciate to send it to me at this mail: <a href="mailto:info@hobby-shop.qc.ca">info@hobby-shop.qc.ca</a> <br />
        <br />
thanks in advance for your help</p>
    </td>
    <td width="161"> </td>
    <td width="386"> <div align="right">
      <p>This logo <img  src= 'http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50'/> mean that you can download a PDF file. To read it you need minimum Acrobat reader and you can download it <a href="http://get.adobe.com/reader/">here</a></p>
      <p>Some link will return a TBC. Sorry for any inconveniant. as soon as we will receive or do the PDF it will be updated.</p>
    </div></td>
  </tr>
</table>


<br>







<?php
if (isset($_POST['todo']) && $_POST['todo'] == "search") {    $todo=$_POST['todo'];

$name=$_POST['cat'];
$name1=$_POST['manufacturer_kit'];
$name2=$_POST['year_prod_reel'];
$name3=$_POST['scale'];
$name11=$_POST['car_model'];


//-query  the database table for the post field  

$sql="SELECT  kit_id, kit_number, kit_name, description, manufacturer_kit, manufacturer_reel, scale, engine_detail, year_prod_kit, year_prod_reel, image_id, image_id1, image_id2  FROM kit ";
    $sqlOperand="WHERE";
    if ($name != "cat") {
        $sql = $sql . $sqlOperand . " manufacturer_reel LIKE '%" . $name ."%' ";
        $sqlOperand = " AND ";
    }
    if ($name1 != "kit manufacturer") {
        $sql = $sql . $sqlOperand . " manufacturer_kit LIKE '%" . $name1 ."%' ";
        $sqlOperand = " AND ";
    }
    if ($name2 != "vehicules year manufactured") {
        $sql = $sql . $sqlOperand . " year_prod_reel LIKE '%" . $name2 ."%' ";
        $sqlOperand = " AND ";
    }
    if ($name3 != "scale") {
        $sql = $sql . $sqlOperand . " scale LIKE '%" . $name3 ."%' ";
        $sqlOperand = " AND ";
    }
if ($name11 != "car_model") {
        $sql = $sql . $sqlOperand . " car_model LIKE '%" . $name11 ."%' ";
        $sqlOperand = " AND ";
    }
    if ($sqlOperand == "WHERE") {
           echo  "<p>Please enter a search query</p>";   
    } 

else {
   //   echo '<img src="web-design/sorry.jpg" alt="sorry">';
       	
       // echo "Sorry nothing match your selection / Desolle rien ne correspond a votre selection";
   // echo "run sql: <BR> $sql <BR> and display results";
    }



  //-run  the query against the mysql query function   
   $result=mysql_query($sql);  
   
  //-make the header of the table   
   
   echo "  <table align=center width=\"1340\" border=\"\">\n";
   echo "    <tr>\n";
   echo"  <td nowrap align=center width='95'>  kit manufacturer  \n";		
   echo"  <td nowrap align=center width='55'>	scale \n";		
   echo"  <td nowrap align=center width='90'>	kit number \n";		
   echo"  <td nowrap align=center width='290'>	kit name \n";		
   echo"  <td nowrap align=center width='400'>	description \n";
   echo"  <td nowrap align=center width='125'>	vehicule year \n";		
   echo"  <td nowrap align=center width='80'>	complete engine detail\n";		
   echo"  <td nowrap align=center width='80'>	Select Picture to get bigger\n";
   echo"  <td nowrap align=center width='75'>	instruction sheet\n";
   echo"  <td nowrap align=center width='75'>	box contain\n";
   echo "    <tr>\n";

   //-create  while loop and loop through result set   
   while($row=mysql_fetch_array($result)){   
         $description  =$row['description_eng'];   
         $manufacturer_kit=$row['manufacturer_kit']; 
	 $scale=$row['scale'];
	 $car_model=$row['car_model'];
	 $cat=$row['cat'];
	 $manufacturer_reel=$row['manufacturer_reel'];   
         $kit_id=$row['kit_id']; 
	 $kit_number=$row['kit_number'];
	 $kit_name=$row['kit_name'];
	 $engine_detail=$row['engine_detail'];
	 $year_prod_reel=$row['year_prod_reel'];
	 $image_id=$row['image_id'];
	 $image_id1=$row['image_id1'];
	 $image_id2=$row['image_id2'];


	   
   //-create  table of item during he while loop
   
echo "  <table align=center width=\"1340\" border=\"\">\n";		   
echo"  <td nowrap align=center width='95'>  $manufacturer_kit  \n";	
echo"  <td nowrap align=center width='55'>  $scale  \n";
echo"  <td nowrap align=center width='90'>	$kit_number \n";		
echo"  <td nowrap align=center width='290'>	$kit_name \n";		
echo"  <td nowrap width='400'>	$description_eng \n";
echo"  <td nowrap align=center width='125'>	$year_prod_reel \n";		
echo"  <td nowrap align=center width='80'>	$engine_detail \n";	
echo"  <td nowrap width='80'> <a href=".$image_id.">   <img src='".$image_id."' width='75' height='50' border='0'/>";
echo"  <td nowrap width='75'> <a href= ".$image_id1.">   <img src= 'http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50' border='0'/>";
echo"  <td nowrap width='75'> <a href=".$image_id2.">   <img src='http://www.scale24-25.com/images/PDF_logo.gif' width='50' height='50' border='0'/>";
echo "    </tr>\n";
echo "    </table>\n"; 
echo "    </tr>\n";
echo "    </table>\n";


   }   
   }  
   else{   
   echo  "<p>Please enter a search query</p>";   
   }   
   
?>  


  



</body>

</html>

 

I know it's a big mess I will work on that as soon as possible.

 

thanks in adavance

 

sebastien

Link to comment
Share on other sites

I'm not even going through all that, I'll just show you how to error check a select query.

 

$sql = "SELECT fld FROM tbl";
if ($result = mysql_query($sql)) {
  if (mysql_num_rows($result)) {
    // $result is good to use.
  } else {
    // no results found, display message.
  }
} else {
  // query failed, handle error.
}

Link to comment
Share on other sites

Hi thorpe!!

 

maybe this will help..

 

below is the original query.

 

<?php
//  strat of drop down  ///
$q=mysql_query("SELECT DISTINCT manufacturer_reel FROM kit ORDER BY manufacturer_reel");
echo '<select name="manufacturer_reel"><option value="reel manufacturer">Please Choose an Option</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['manufacturer_reel'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";
//  end of drop down  ///
echo " <br> \n";
echo " <br> \n";
//  end of drop down  ///

?>

 

it was change to be able to call and populate a second dropdown. see the new code below.

 

///////// Getting the data from Mysql table for first list box//////////
$q=mysql_query("SELECT DISTINCT manufacturer_reel,manufacturer_reel_id FROM kit order by manufacturer_reel"); 
///////////// End of query for first list box//////////



//////////        Starting of first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Please Choose an Option</option>";
while($row = mysql_fetch_array($q)) { 
if($row['manufacturer_reel_id']==@$cat){echo "<option selected value='$row[manufacturer_reel_id]'>$row[manufacturer_reel]</option>"."<BR>";}
else{echo  "<option value='$row[manufacturer_reel_id]'>$row[manufacturer_reel]</option>";}
}
echo "</select>"; 



//////////////////  This will end the first drop down list ///////////

<?php /////// for second drop down list we will check if manufacturer_reel is selected else we will display all the car_model///// 
if(isset($cat) and strlen($cat) > 0){
$q=mysql_query("SELECT DISTINCT car_model FROM kit where manufacturer_reel_id=$cat order by car_model"); 
}else{$q=mysql_query("SELECT DISTINCT car_model FROM kit order by car_model"); } 

////////// end of query for second car_model drop down list box ///////////////////////////

echo '<select name="car_model"><option value="car_model">Please Choose an Option</option>';
while($row = mysql_fetch_array($q)) {
$thing = $row['car_model'];
echo '<option>'.$thing.'</option>';
}
echo "</select>";

echo " <br> \n";
echo " <br> \n";

?>

 

I'm pretty sure the error came from this change. someone can look at it and let me know.

 

these code came from the form.

 

thanks

 

sebastien

Link to comment
Share on other sites

The logic that thorpe showed in his post, should be used for every SELECT query you have in your code so that you can handle when an error of some kind occurs with the query and when the query matches no data. For INSERT, UPDATE, and DELETE queries, you would use similar logic but use mysql_affected_rows instead of mysql_num_rows.

 

Where he put the comment // $result is good to use is where you would build your select menu, because the query executed without an error and it matched one or more rows in your table. Also by putting the code that access the result of the query at this point in the logic, you prevent the generation of follow-on errors that make your web pages look unprofessional.

 

Where he put the comment // no results found, display message is where you would output a message such as 'No manufacturers were found' or do you intend your code to produce a select menu that has no choices and a person wondering why the menu doesn't work?

 

Where he put the comment // query failed, handle error. is where you would output an error message to the visitor to let him know that the page experienced fatal problem that prevents it from working - 'Sorry, a server error is preventing this page from working!' AND where you report and display/log the error information so that you can find and fix the problem. For mysql_query errors (and for mysql_connect and mysql_select_db errors), you can use mysql_error to get the reason why the query failed. If you use trigger_error to handle the error, you can use php's built in error_reporting/display_errors, log_errors settings to cause the error to be printed during development and logged on a live server.

 

For that block of code, you should do something like -

} else {
     // query failed, handle error.
    $user_message = "Sorry, a server error is preventing this page from working!";
    $system_message = "Query failed: $sql<br />\nReason: " . mysql_error();
    echo $user_message;
    trigger_error($system_message);
}

 

To get the above trigger_error() code to work, you should always have error_reporting set to E_ALL (or to a -1) and for development, display_errors should be on, and on a live server, display_errors should be off and log_errors should be on.

 

Not all query errors are due to things that are under your control. Once you debug why your query is failing and fix the problem, you still need logic like this in your code so that query errors due to actual problems on the server that are out of your control are handled properly by your code.

Link to comment
Share on other sites

As to why you are getting an error at the mysql_fetch_array statement, no one here can tell that just by looking at your query. There's nothing logically wrong with it, which is why always using the above suggested logic is important.

 

Here is what the code for that query should look like -

 

<?php
$sql = "SELECT DISTINCT manufacturer_reel,manufacturer_reel_id FROM kit order by manufacturer_reel";
if ($result = mysql_query($sql)) {
if (mysql_num_rows($result)) {
	echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Please Choose an Option</option>";
	while($row = mysql_fetch_array($result)) { 
		if($row['manufacturer_reel_id']==@$cat){echo "<option selected value='$row[manufacturer_reel_id]'>$row[manufacturer_reel]</option>"."<BR>";}
		else{echo  "<option value='$row[manufacturer_reel_id]'>$row[manufacturer_reel]</option>";}
	}
	echo "</select>"; 
} else {
	// no results found, display message.
	echo 'No manufacturers were found';
}
} else {
     // query failed, handle error.
    $user_message = "Sorry, a server error is preventing this page from working!";
    $system_message = "Query failed: $sql<br />\nReason: " . mysql_error();
    echo $user_message;
    trigger_error($system_message);
}
?>

 

Provided you have the error_reporting and display_errors/log_errors settings set as suggested, the above code will tell you if and why your query is failing.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.