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
$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']; }
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
use "@" in front of "$_POST['kategoria']" and "mysql_fetch_array" and you won't see those warnings anymore!
<?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?