insert problem

Codes here !

Moderators: macek, egami, gesf

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

Re: insert problem

Postby tsapen » 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.

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 0 guests

cron