insert problem

  • Thread starter Thread starter Anonymous
  • Start date Start date
A

Anonymous

Guest
I suppose you want to place six random numbers into ONE DB record.
If so then you should insert them using ONE "isert" statement since provided table structure shows that you have them in one record.
Use the following:

Code:
  $str="";
  foreach($randgen As $index => $value){
    echo "value: ".$value."\n";
    $str.="'$value',";
  }
  $str=substr($str,0,-1);
  $query = "INSERT INTO draws VALUES(".$str.")";
  $result = mysql_query($query);
   if($result)
     echo mysql_affected_rows()." draw inserted into database.";
  echo"<br>";

instead of

dabith said:
Code:
  foreach($randgen As $index => $value){
    echo "value: ".$value."\n";
    $query = "INSERT INTO draws VALUES('".$value."')";
    $result = mysql_query($query);
     if($result)
       echo mysql_affected_rows()." draw inserted into database.";
  }
  echo"<br>";

It should work. I hope so.
 
Back
Top