Jump to content

mysql_fetch_array(): supplied argument is not a valid ......


scaleautostyle

Recommended Posts

Hi everyone!!

 

I finish to do my second populating drop down list. it's not realy the display I was looking but for now it will be good. but when I click on my serach button I receive this erro.

 

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\scale24-25\search-keyword.php on line 112

 

this is what line 112 is in the search file.

 

//-create  while loop and loop through result set 

  while($row=mysql_fetch_array($result)){  <--------------  line 112

       

 

here's the code of my form...

 

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

<html>

<head>
<title>1/24 - 1/25 scale model database</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,13,330,53,98,54,90,92,670,99,668,54,889,51,886,5" href="http://www.scale-auto-style.com" alt="" />
</map>
<?php

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

$manufacturer_reel=$_POST['manufacturer_reel'];

$query="select * from kit where  ";

////////// 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 colspan="3"><table width="100%" border="0">
      <tr>
        
  </tr>
  <tr>
    <td><div align="right"></div></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td><div align="right">Echelle du modele</div></td>
    <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> </td>
    <td><div align="right"></div></td>
  </tr>
  <tr>
    <td><div align="right">Nom du manufacturier automobile</div></td>
    <td align="center"><?php
//  strat of drop down  ///
/*
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

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

/////// 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){
$quer=mysql_query("SELECT DISTINCT car_model FROM kit where manufacturer_reel_id=$cat order by car_model"); 
}else{$quer=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 first drop downlist /////////
echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>";
while($noticia2 = mysql_fetch_array($quer2)) { 
if($noticia2['manufacturer_reel_id']==@$cat){echo "<option selected value='$noticia2[manufacturer_reel_id]'>$noticia2[manufacturer_reel]</option>"."<BR>";}
else{echo  "<option value='$noticia2[manufacturer_reel_id]'>$noticia2[manufacturer_reel]</option>";}
}
echo "</select>";
//////////////////  This will end the first drop down list ///////////

//////////        Starting of second drop downlist /////////
echo "<select name='subcat'><option value=''>Select one</option>";
while($noticia = mysql_fetch_array($quer)) { 
echo  "<option value='$noticia[car_model]'>$noticia[car_model]</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> </td>
    <td> </td>
    <td><div align="right"></div></td>
  </tr>
  <tr>
    <td><div align="right">Nom du manufacturier de modele reduit</div></td>
    <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><div align="right"></div></td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td><div align="right">Annee de fabrication du Vehicule</div></td>
    <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">Year of production of the vehicule</div></td>
  </tr>
  <tr>
    <td> </td>
    <td> </td>
    <td> </td>
  </tr>
  <tr>
    <td> </td>
    <td align="center"> </td>
    <td> </td>
  </tr>
  <tr>
    <td><div align="right"><strong></strong></div></td>
    <td align="center">
<?php

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


?>
<td><div align="left"><strong></strong></div></td>

      
    </table>    





</body>

</html>


    

 

and this the search file

 

<?php

include_once("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/catalog/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,13,330,53,98,54,90,92,670,99,668,54,889,51,886,5" href="http://www.scale-auto-style.com" alt="" />
</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"><div align="center"><a href="search-db-foreach.php"><img src="catalog/images/design_web/othersearch.jpg" border="0" alt="search" width="150" height="96"></a></div></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['subcat'];


//-query  the database table for the post field  

$sql="SELECT  kit_id, kit_number, kit_name, description_eng, description_fr, manufacturer_kit, manufacturer_reel, manufacturer_reel_id, 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 . " cat LIKE '%" . $name ."%' ";
        $sqlOperand = " AND ";
    }
    if ($name1 != "kit manufacturer") {
        $sql = $sql . $sqlOperand . " manufacturer_kit LIKE '%" . $name1 ."%' ";
        $sqlOperand = " AND ";
    }
if ($name11 != "subcat") {
        $sql = $sql . $sqlOperand . " subcat LIKE '%" . $name11 ."%' ";
        $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 ($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_eng  =$row['description_eng'];   
         $manufacturer_kit=$row['manufacturer_kit']; 
	 $scale=$row['scale']; 
	 $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>

 

so what I do wrong. I knowI forgot something but what????

 

thanks in advance for your help

 

sebastien

Link to comment
Share on other sites

You should be checking for successful query execution and handling any problems. That error is a good indication that the query failed. Echo the query string, and any errors returned.

 

Pseudo-code

$query = "Your query string";
if( $result = mysql_query($query) ) {
     while( $array = mysql_fetch_assoc($result) ) {
          // do stuff for successful query
     }
} else {
     echo "<br>Query string: $query<br>Failed with error: ". mysql_error() . '<br>';
}

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.