Reputation: 49
This for array only loops once, instead of 3 (numbers of files i want to insert into the database), i've been looking at it for 2 hours now, and cant seem to locate the error. Please help.. (It's the insert for loop that only runs once, the 2 foreach works fine)
$upload = $_FILES['upload'];
$i=0;
foreach($upload['tmp_name'] as $key=>$value){
$tmp_name[$i]=$value;
$i++;
}
$i=0;
foreach($upload['name'] as $key=>$value){
$name[$i]=$value;
$i++;
}
for($i=0; $i < count($name); $i++){
$insert_image = "INSERT INTO ".$image_table." (";
$lastImage = end($image_rows);
for ($i=0; $i < count($image_rows); $i++){
$insert_image .= "".$image_rows[$i]."";
if($image_rows[$i] != $lastImage){
$insert_image .= ", ";
}
}
$insert_image .= ") VALUE ('".$upload['name'][$i]."', '".$latest_id."')";
mysql_query($insert_image) or die(mysql_error ());
}
HTML: <input type='file' name='upload[]'>
Upvotes: 0
Views: 1275
Reputation: 4014
Probably because you are reassigning the value of $i:
for ($i=0; $i < count($image_rows); $i++){
Upvotes: 5