insert problem

Codes here !

Moderators: egami, macek, gesf

Post Reply
tsapen
New php-forum User
New php-forum User
Posts: 6
Joined: Sun Oct 13, 2002 1:26 pm
Contact:

Sun Oct 13, 2002 1:35 pm

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: Select all

  $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 wrote:

Code: Select all

  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.
Mike Tsapenko
Chief of Web-development Dept.
AlarIT
www.AlarIT.com

Post Reply