Why is my insert row only inserting the final row from the loop into the database rather than just inserting one
?php
session_start();
if(is_user_logged_in()) {
global $wpdb;
$id = get_current_user_id();
$recoveryID = null;
// $results = $wpdb-get_results('SELECT * FROM wp_recovery_details where not exists (select driverID ,recoveryID from wp_recovery_bids where driverID='$id')');
//
$results = $wpdb-get_results('SELECT * FROM wp_recovery_details');
//
// EXISTS (select driverID ,bidAmount from wp_recovery_bids)
// output data of each row
foreach ($results as $row) {
// $recoveryID = $row-recoveryID;
// $result = $wpdb-get_results('select * from wp_recovery_details where not exists(select driverID from wp_recovery_details where recoveryID ='$recoveryID' ');
// if(count($result) 0){
// $numberPlate = str_replace(' ', '', $row - custNoPlate);
//
$_SESSION['recoveryID'] = $row - recoveryID;
$image = $row - imageURL;
echo
table role='table'
thead
tr
thVehicle/th
thLocation/th
thDestination/th
thEstimated Time of Arrival/th
thYour price/th
/tr
/thead
tr
th
form method='post' action =''
h1 .$row - recoveryID. /h1
img src='https://www.recovermenow.co.uk/{$image}'
width='150' height='70'/
. $row - custNoPlate.
th .$row - pickUp. /th
th .$row - destination. /th
thinput type='time' name='eta'//th
thinput type='text' name='price'//th
thinput type='submit' name='submit'//th
/form
/table;
// }
};
if(isset($_POST['submit'])){
$table_name = $wpdb-prefix.'recovery_bids';
$bidAmount = $_POST['price'];
$estimatedTime = $_POST['eta'];
$bidID = rand(10,10000);
$driverID = get_current_user_id();
$recoveryID = $_SESSION['recoveryID'];
$wpdb-insert($table_name, array(
'bidID' = $bidID,
'bidAmount' = $bidAmount,
'estimatedTime'= $estimatedTime,
'driverID' = $driverID,
'recoveryID' = $recoveryID ,
),
array(
'%s',
'%s',
'%s',
'%s',
'%s',
));
}
} else{
echo Login to view this page;
}
?
Topic id wp-insert-post Wordpress sql
Category Web