Remove button (not hide) if value being updated already exists

  css, html, php, wordpress

This code updates a database table to approved, regardless of the current database value. I need the form HTML code below the PHP code here to be executed only if the value being updated is not "approved" meaning the button should only display if the value is anything else but approved. I don’t want the users to see the button for updating the value to approved when the value approved already exists.
I know how to wrap the code inside an if condition but I don’t know what condition to supply given I’m using $wpdb->update.

global $wpdb;
$msg = '';
if(isset($_POST['actionp'.$appointment['id']])){
$wpdb->update (

'wp_bkntc_appointment_customers',

 array('status' => 'approved' ),

 array ('appointment_id' => $appointment['id'])

);
$msg ='Update Successful';
}

$pick_shift = 'actionp'.$appointment['id'];

return '<div class="d-flex align-items-center">'.$customersTxt.'<br><form action=' . $_SERVER['PHP_SELF'] . '?page=booknetic&module=appointments method="POST" style="width:100%; white-space: nowrap;">
<input type="submit" style="background:green; color:#fff; border-radius:10px;" onclick='return confirm("Are you sure you want to PICK the shift?");' name="'.$pick_shift.'" class="pckbutton" value="Pick" /></form></div>';

Something like

if (value == "approved") {
   return 'Already Approved';
} elseif {
return '<div class="d-flex align-items-center">'.$customersTxt.'<br>
<form action=' . $_SERVER['PHP_SELF'] . '?page=booknetic&module=appointments 
method="POST" style="width:100%; white-space: nowrap;">
<input type="submit" style="background:green; color:#fff; border-radius:10px;" 
onclick='return confirm("Are you sure you want to PICK the shift?");' 
name="'.$pick_shift.'" class="pckbutton" value="Pick" /></form></div>';
}

Source: Ask PHP

LEAVE A COMMENT