php - Multiple records inserted from one form -
i have form upload data multiple mysql tables , part of requires 4 identical sections upload video location data 1 table. 4 video sections won't filled out might left blank, number 4 having data. below part of form showing 1 video location upload, needs appear 4 times on form:
<tr> <td>video 1:</td> <td></td> </tr> <tr> <td>location</td> <td><input type="text" name="location"></td> </tr> <tr> <td>park video</td> <td><input type="checkbox" name="park_id_video" value="<?=$park_id?>">park video</td> </tr> <tr> <td>ride</td> <td> <select name="ride_id_video"> <option value="">select ride</option> <?php echo $options ?> </select> </td> </tr>
below shows typical insert query use , use this. have never had insert multiple records though , not sure how 4 sets of data can uploaded in 1 query. , if of 4 sets of data blank blank record won't inserted.
$news_id = $pdo->lastinsertid() ; $location = $_post['headline']; $park_id_video = $_post['park_id_video']; $ride_id_video = $_post['ride_id_video']; $query4 = $pdo->prepare('insert tpf_videos (location, park_id, ride_id, news_id) values (?, ?, ?, ?)'); $query4->execute(array($location, $park_id, $ride_id, $news_id));
from have read needs array don't know how this. can me modify form , query make work?
thanks.
just rename form's field filed_name[]
, using loop able perform multiple insert.
for ($i = 0; $i < count($_post['location']); $i++){ //do insert code. }
Comments
Post a Comment