Page 1 of 1

[SOLVED] array insert

Posted: Tue Aug 31, 2004 8:23 am
by ol4pr0
tried something stupid like the following

Code: Select all

foreach ($nombres_array as $nombres_insert)
$query = 'INSERT INTO opertunidades (mail) VALUES ("'.$nombres_insert.'")' or die (mysql_error());
$result = mysql_query($query);
HOwever this doesnt work, well it does but only inserts the first name of the array. How do i make a insert that will insert them all. like below

id name
1 jack
2 jill
3 diddly

Posted: Tue Aug 31, 2004 8:27 am
by markl999
You just appear to be missing {} , without them only the $query = line is 'inside' the foreach. Also the or die ... should be part of the mysql_query not the query string.

Code: Select all

foreach ($nombres_array as $nombres_insert){
    $query = "INSERT INTO opertunidades (mail) VALUES ('".$nombres_insert."')";
    mysql_query($query) or die(mysql_error());
}

Posted: Tue Aug 31, 2004 8:32 am
by ol4pr0
thx worked great

yea stupid.. copy and pasted the version i was busy editing lol.
it was only inserting the 1st one.. but now they luckly did them all hehe.