Select data from foreach loop and send it to wordpress database
The project that I'm working on have a user login section. Once the user logged in, they should be able to see a list of orders that they made in the past which are stored in the database. The list view is done by a foreach function. In this case, the user must be able to rebook any of those past order by one click and it should send the same data back to the database as a new row or duplicate the same row with a new id. My code looks like this:
form method="post" action=""
foreach ( $row as $row ){ ?
div Previous Trip from:
?php echo $row- your_departing .' to : '.$row- your_destination; ?
?php $depart = $row- your_departing;
$dest = $row- your_destination;
?
button type="submit" name="rebook" class="signupbtn"REBOOK/button
/div
?php } ?
/form
if ( isset( $_POST["rebook"] ) != "" ) {
$table = $wpdb-prefix."Savedata";
$wpdb-insert(
$table,
array(
'your_destination' = $dest,
'your_departing' = $depart
)
);
}
?
I wrote this code to insert the data as a new row. Do I miss something in the code? Can anyone suggest an easy way to get this done? Any helps would be great. Thanks
Topic duplicates forms database Wordpress
Category Web