Problem with simple searching script

Discussion in 'PHP' started by tua1, May 19, 2008.

  1. #1
    Hello!

    I have a problem with my searching script.

    My html form:


         <form id="frmPokaz" action="pokaz.php" method="post" >
    	  <fieldset id="Pokaz"><legend>Wybierz swoja kategorie</legend><table id="tblPokaz" >
    	   <tr>
    	    <td class="underline">Dyscyplina:</td>
    	    <td>
             <select name="dyscyplina" id="select">
    	     <option selected value="0"><strong>Wszystkie</strong></option>
    	     <option value="1">Koszykówka</option>
    	     <option value="2">Pilka Nozna</option>
    	     <option value="3">Sztuki walki</option>
    	     <option value="4">Lekkoatletyka</option>
    	     <option value="5">Terefere</option>
    	     <option value="6">Biegi</option>
    	     <option value="7">Suplementy</option>
    	     </select>	   </td>
    	   <td class="underline"> Kategoria:	   </td>
    	   <td>Odziez	 </td>
    	   <td>
    	    <input name="kategoria" type="checkbox"  class="checkbox" value="1" >	   </td>  
    	   <td>Sprzet</td>
    	   <td><input name="kategoria" type="checkbox" class="checkbox" value="2">	   </td>
    	   <td>Inne</td>
    	   <td><input name="kategoria" type="checkbox"  class="checkbox" value="3"  >	   </td>
    	   <td><input type="submit" class="submit" name="submit" id="pokaz" value="Pokaz"></td>
    	   </tr>
    	   
    	   </table></fieldset>
          </form>
    Code (markup):

    My php script:

    <?php
    require_once ("include/polaczenie.php");
    
    //$_POST['kategoria']= array();
    
    foreach ($_POST['kategoria'] as $pt) { 
     $in1 .= "'" . $pt . "',"; 
     
     }
    $in1 = substr($in1,0,strlen($pt)-1); 
    
    $sql = "select ID_prod, ID_kat, ID_dyscyplina, nazwa_prod, cena, dostepny, opis_prod from produkty where ID_kat IN (" . $in1  . ") and ID_dyscyplina=" . $_POST['dyscyplina'] . ";";
    //echo $sql;
    
    $query = mysql_query($sql);
    
    while ($row = mysql_fetch_array($query)) { 
     echo '<p class="p_account_php">',$row['nazwa_prod'],'</p> ',$row['nazwa_prod']; 
    }
    
    ?>
    Code (markup):

    The error is:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\WebServ\httpd\Runners2\pokaz.php on line 241

    Could anyone help?

    Regards
     
    tua1, May 19, 2008 IP
  2. singh.ajit05

    singh.ajit05 Peon

    Messages:
    83
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    $sql = "select ID_prod, ID_kat, ID_dyscyplina, nazwa_prod, cena, dostepny, opis_prod from produkty where ID_kat IN (" . $in1 . ") and ID_dyscyplina=" . $_POST['dyscyplina'] . ";";

    require_once ("include/polaczenie.php");

    //$_POST['kategoria']= array();

    foreach ($_POST['kategoria'] as $pt) {
    $in1 .= "" . $pt . ",";

    }
    $in1 = substr($in1,0,strlen($pt)-1);

    $sql = "select ID_prod, ID_kat, ID_dyscyplina, nazwa_prod, cena, dostepny, opis_prod from produkty where ID_kat IN (" . $in1 . ") and ID_dyscyplina=" . $_POST['dyscyplina'] . ";";
    //echo $sql;

    $query = mysql_query($sql);

    while ($row = mysql_fetch_array($query)) {
    echo '<p class="p_account_php">',$row['nazwa_prod'],'</p> ',$row['nazwa_prod'];
    }
     
    singh.ajit05, May 19, 2008 IP
  3. tua1

    tua1 Guest

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Warning: Invalid argument supplied for foreach() in C:\WebServ\httpd\Runners2\pokaz.php on line 212

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\WebServ\httpd\Runners2\pokaz.php on line 223 :confused:
     
    tua1, May 21, 2008 IP
  4. Sphinks

    Sphinks Active Member

    Messages:
    1,102
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    78
    #4
    use "@" in front of "$_POST['kategoria']" and "mysql_fetch_array" and you won't see those warnings anymore!
     
    Sphinks, May 22, 2008 IP
  5. tua1

    tua1 Guest

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    <?php
    	  
    	require_once ("include/polaczenie.php");
    
    //$_POST['kategoria']= array();
    
    foreach (@$_POST['kategoria'] as $pt) { 
     $in1 .= "'" . $pt . "',"; 
     
     }
    $in1 = substr($in1,0,strlen($pt)-1); 
    
    $sql = "select ID_prod, ID_kat, ID_dyscyplina, nazwa_prod, cena, dostepny, opis_prod from produkty where ID_kat IN (" . $in1  . ") and ID_dyscyplina=" . $_POST['dyscyplina'] . ";";
    //echo $sql;
    
    $query = mysql_query($sql);
    
    while ($row = @mysql_fetch_array($query)) { 
     			{ 
     	echo '<p class="p_szukaj_php">',$row['nazwa_prod'],'</p> 
     		<table class="szukaj_php" cellpadding="5">
    		  <tr>
    			<td rowspan="2" valign="top" align="left" cellpadding="5"><img src="images/img_male/',$row['ID_prod'],'.jpg"/>							        </td>
    			<td  colspan="4" valign="top" width="400" align="left">',$row['opis_prod'],'</td>
    		</tr>
    		<tr>
    			<td align="left"  valign="top">Cena: ',$row['cena'],'</td>
    			
    		 
    			 <td align="left" valign="top">Dostepny: ',$row['dostepny'],'</td>
    			 <td align="left"  valign="top"><a href="opinie.php"><input type="submit" class="submit"  value="Opinie"></a></a></td>
    			 <td align="left"  valign="top" align="right"><a href=""><input type="submit" class="submit"  value="Do Koszyka"></a></td>
    		 </tr>
    		</table>
    		<p class="p_szukaj_php"></p>';  
    			
    }
    }
    ?>
    Code (markup):
    I did this but nothing work:

    Warning: Invalid argument supplied for foreach() in C:\WebServ\httpd\Runners2\pokaz.php on line 212

    I don't know how to debug "Invalid argument supplied for foreach()"

    Anybody?
     
    tua1, May 22, 2008 IP