.chester Posted May 27, 2012 Share Posted May 27, 2012 It's one of those questions again. I'm getting Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given on line 12, the one with the while() statement: $sqlTranzactii="select id_tranzactie, DATE_FORMAT(data_tranzactie,'%d-%m-%y') as data_tranzactie, nume_cumparator, adresa_cumparator from tranzactii where comanda_onorata=0"; $resursaTranzactii=mysql_query($sqlTranzactii); while($rowTranzactie=mysql_fetch_array($resursaTranzactii)) form action="prelucrare_comenzi.php" method="post"> Data comenzii: <b><?php echo $rowTranzactie['data_tranzactie']?></b> <div style="width:500px; border:1px solid #ffffff; background-color:#c0c0c0; padding:5px"> <b><?php echo $rowTranzactie['nume_cumparator']?></b><br> <?php echo $rowTranzactie['adresa_cumparator']?> I tried googling the issue, but I haven't found anything exactly like my problem. I'm sure it's something trivial that I'm missing, though. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/263212-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/ Share on other sites More sharing options...
smoseley Posted May 27, 2012 Share Posted May 27, 2012 Your query is throwing an exception. My guess is either you have a typo in one of your columns, or data_tranzactie is not a valid DATE or DATETIME column. Quote Link to comment https://forums.phpfreaks.com/topic/263212-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1348967 Share on other sites More sharing options...
smoseley Posted May 27, 2012 Share Posted May 27, 2012 Try adding a check for mysql_error() and echo it so you can see exactly where it's failing. Quote Link to comment https://forums.phpfreaks.com/topic/263212-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1348968 Share on other sites More sharing options...
.chester Posted May 27, 2012 Author Share Posted May 27, 2012 data_tranzactie is actually timestamp format. Could you please explain where in the code should I add the mysql_error? I've never used it before. Quote Link to comment https://forums.phpfreaks.com/topic/263212-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1348974 Share on other sites More sharing options...
.chester Posted May 27, 2012 Author Share Posted May 27, 2012 I've tried adding mysql_error() as explained by some other forumites, the page stays exactly the same, with the same error on line 12 (even though line 12 isn't even relevant anymore, as it contains the mysql_error() code). I've tried running the query directly in the mysql window, it works perfectly and returns what it should. I'm stumped. Quote Link to comment https://forums.phpfreaks.com/topic/263212-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1348988 Share on other sites More sharing options...
.josh Posted May 27, 2012 Share Posted May 27, 2012 change this: $resursaTranzactii=mysql_query($sqlTranzactii); to this: $resursaTranzactii=mysql_query($sqlTranzactii) or die(mysql_error()); do you see any error messages displayed? Quote Link to comment https://forums.phpfreaks.com/topic/263212-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1348993 Share on other sites More sharing options...
.josh Posted May 27, 2012 Share Posted May 27, 2012 where are you actually connecting to your database? Do you have a mysql_connect() and mysql_select_db() somewhere above the posted code? Is the posted code within a function and your connect/select_db in some other function or outside of the function? Quote Link to comment https://forums.phpfreaks.com/topic/263212-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1348994 Share on other sites More sharing options...
.chester Posted May 28, 2012 Author Share Posted May 28, 2012 UPDATE: <?php include("autorizare.php"); include("admin_top.php"); mysql_connect("localhost", "root", ""); mysql_select_db("anticariat"); ?> <h1>Comenzi</h1> <b>Comenzi inca neonorate</b><br> <?php /* afisam lista comenzilor neonorate*/ $sqlTranzactii="select id_tranzactie, data_tranzactie, nume_cumparator, adresa_cumparator from tranzactii where comanda_onorata=0"; $resursaTranzactii=mysql_query($sqlTranzactii) or die(mysql_error()); print mysql_error(); while($rowTranzactie=mysql_fetch_array($resursaTranzactii)) print_r($sqlTranzactii); print_r($resursaTranzactii); { ?> <form action="prelucrare_comenzi.php" method="post"> Data comenzii: <b><?php echo $rowTranzactie['data_tranzactie']?></b> <div style="width:500px; border:1px solid #ffffff; background-color:#c0c0c0; padding:5px"> <b><?php echo $rowTranzactie['nume_cumparator']?></b><br> <?php echo $rowTranzactie['adresa_cumparator']?> <table border="1" cellpadding="4" cellspacing="0"> <tr> <td align="center"><b>Carte</b></td> <td align="center"><b>Nr. Buc</b></td> <td align="center"><b>Pret</b></td> <td align="center"><b>Total</b></td> </tr> <?php $sqlCarti="select titlu, nume_autor, pret, nr_buc from vanzari, carti, autori where carti.id_carte=vanzari.id_carte and carti.id_autor=autori.id_autor and id_tranzactie=".$rowTranzactie['id_tranzactie']; $resursaCarti=mysql_query($sqlCarti); while($rowCarte=mysql_fetch_array($resursaCarti)) { print '<tr><td>'.$rowCarte['titlu'].' de '.$rowCarte['nume_autor'].'</td> <td align="right">'.$rowCarte['nr_buc'].'</td> <td align="right">'.$rowCarte['pret'].' </td>'; $total=$rowCarte['pret'] * $rowCarte['nr_buc']; print '<td align="right">'.$total.'</td></tr>'; $totalGeneral=$totalGeneral+$total; } ?> <tr> <td colspan="3" align="right">Total comanda:</td><td><?php echo $totalGeneral?> lei</td> </tr> </table> <input type="hidden" name="id_tranzactie" value="<?php echo $rowTranzactie['id_tranzactie']?>"> <input type="submit" name="comanda_onorata" value="Comanda onorata!"> <input type="submit" name="anuleaza_comanda" value="Anuleaza comanda"> </div> </form> <?php } ?> </body> </html> I worked on it some more and there's a wee bit of progress. At least the table is showing now. I also added print_r() to $sqlTranzactii and $resursaTranzactii. The result: I don't know what to make of what print_r() is displaying. Is there no data being extracted from the database? Quote Link to comment https://forums.phpfreaks.com/topic/263212-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1349144 Share on other sites More sharing options...
PFMaBiSmAd Posted May 28, 2012 Share Posted May 28, 2012 The current problem is your query on line 34 is failing. You would need to use the mysql_error() logic for that query to find out why it is failing. Quote Link to comment https://forums.phpfreaks.com/topic/263212-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1349176 Share on other sites More sharing options...
.chester Posted May 28, 2012 Author Share Posted May 28, 2012 As predicted, it was a minor thing. The nr_buc column was actually called nr_bucati. As soon as I changed it, everything worked perfectly. Thanks for the help everyone, much obliged! Quote Link to comment https://forums.phpfreaks.com/topic/263212-warning-mysql_fetch_array-expects-parameter-1-to-be-resource-boolean-given/#findComment-1349195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.