0

When I run my code I continue to get these errors and I can't figure out what I need to fix.

Here's the errors I'm recieving.

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in

my code:

<?php if(isset($_POST['dt'])){
  $ab=$_POST['dt'];
  $maconnexion=mysql_connect("localhost","root","");
  $mabase=mysql_select_db("gestion de production",$maconnexion);
  $requete="select p.num,e.mat,e.nom,a.codea,a.designation,a.stock from employe e,production p,article a where e.mat=p.mat and p.codea=a.codea and p.date de naissance='$ab'";
  $resultat=mysql_query($requete,$maconnexion);}
function stock(){
  global $ab; global $resultat;
  global $maconnexion;
  ?>
  <table border=1>
    <tr>
      <td>num
      <td>mat
      <td>nom
      <td>codea
      <td>designation
      <td>qt
    <?php
    while($ligne=mysql_fetch_array($resultat,MYSQL_NUM)){
      echo"<tr>";
      echo"<td>$ligne[0]<td>$ligne[1]<td>$ligne[2]<td>$ligne[3]<td>$ligne[4]<td>$ligne[5]";
      $re="insert into wproduction values('$ligne[0]','$ab','$ligne[1]','$ligne[2]','$ligne[3]','$ligne[4]','$ligne[5]')";
      $res=mysql_query($re,$maconnexion);} }
if(isset($_POST['a'])){
  stock();
}
?>
m59
  • 42,346
  • 14
  • 112
  • 132
arok
  • 1,783
  • 7
  • 26
  • 54
  • what does `mysql_error()` print? – andrewsi Dec 15 '13 at 16:06
  • i tried it showing Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-12.1\www\my portable files\production\saisie.php on line 38 – arok Dec 15 '13 at 16:15
  • no, it doesn't. That's a PHP error; if you echo out the contents of `mysql_error()`, you'll see exactly what the database error is. – andrewsi Dec 15 '13 at 16:17
  • it showing 2013-12-03mysql_error() please help me – arok Dec 15 '13 at 16:23

1 Answers1

0

You have to check if $resultat === false. If it does , it´s a mysql error so you must intercept and not parse it in the while.

David 'mArm' Ansermot
  • 5,839
  • 6
  • 44
  • 80
  • i checked it showing select p.num,e.mat,e.nom,a.codea,a.designation,a.stock from employe e,production p,article a where e.mat=p.mat and p.codea=a.codea and p.date de naissance='2013-12-03' – arok Dec 15 '13 at 15:59
  • qt Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-12.1\www\my portable files\saisie1.php on line 38 – arok Dec 15 '13 at 16:00
  • 2
    The $resultat varaible isb´t the requedt but the result so if you var_dump it it should be 'resource' type. If it´s a boolean, you have an error on your request so it cant return a valide result. – David 'mArm' Ansermot Dec 15 '13 at 16:02