I have this code which permits me to insert some dates i’ve selected in a database, now this one inserts just one value, not all, it’s like it stops at the first value..
Could you please tell me what i’m doing wrong?
Thanks!
$job_id=$_REQUEST['job_id'];
$dates = explode(",", $_POST['altField']);
foreach($dates as $date){
$sql="INSERT INTO date (job_id,date) VALUES('$job_id','$date')";
mysql_query($sql);
}
Inserts can have multiple value sets so you just need to set the values in the foreach and then outside of it, do the query. you can also do it this way and get the same result,
REMINDER
ALWAYS sanitize your inputs. Not doing so could lead to SQL Injections and cause major issues for you. Look at this Also mysql is not maintained and is suggested to switch to MySqli or PDO.