Use arrays! Very small example:
for($i=1; $i<=$iday; $i++){
echo "Day-$i<br />";
echo '<input type="text" name="i['.$i.']" />';
echo '<textarea name="d['.$i.'].'"></textarea>';
}
Now you can loop through them when you post:
foreach($_POST['i'] as $key=>$val ){
$sql2 = "INSERT INTO sight VALUES('','". $_POST['i'][$key] ."','". $_POST['d'][$key] ."')";
}
I’ve also changed the quotes. You should wrap attribute values in double quotes. There arent really any rules about this, bit in practice that’ll work easier. Also, I really suggest better names for inputs than i
and d
(I made an error in my snippet because I got confused by it haha).
In your specific example, you could also just loop through the days again (just like you did for the inputs), but now using the $i
in your sql string. I’m not showing how, as thta is not the way to go.
1
solved How to separate $_POST values in two two parts and insert it in database [closed]