Well i've been able to find a fix. The page when it loads first gets the value of refnum from the previous submitted page and stores it in the variable $refnum
.
if (isset($_POST['search'])) {
$refnum = $_POST['refnum'];
$paymentstatus = "Paid";
}
Now this current page has another form for updating the record in the database and is supposed to use the value of the $refnum
and it submits to itself.
if ((isset($_POST["form_update"])) && ($_POST["form_update"] == "paymentconfirm")) {
$stmt = $connQlife->prepare("UPDATE cimbooking SET paymentstatus=? WHERE bookingrefnum=?");
$stmt->bind_param('ss', $paymentstatus, $refnum);
$results = $stmt->execute();
$stmt->close();
if($results){
$updateGoTo = "confirm";
$errorGoTo = "error";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header("Location: ". $updateGoTo);
}else{
header("Location: ". $errorGoTo);
}
}
What was happening is that, because it was submitting to itself, the value of the $refnum
was being lost.
So my fix (probably not the best way) was to create a session variable with the value of the $refnum
so that when the page submitted to itself, i could then retrieve the value of the $refnum
from the session and use it to update the record.
if (isset($_POST['search'])) {
$refnum = $_POST['refnum'];
$_SESSION['REFNUM'] = $refnum;
}
if ((isset($_POST["form_update"])) && ($_POST["form_update"] == "paymentconfirm")) {
$paymentstatus = "Paid";
$newrefnum = $_SESSION['REFNUM'];
$query = ("UPDATE cimbooking SET paymentstatus=? WHERE bookingrefnum=?");
$stmt = $connQlife->prepare($query);
$stmt->bind_param('ss', $paymentstatus, $newrefnum);
$results = $stmt->execute();
$stmt->close();
unset($_SESSION['REFNUM']);
if($results){
$updateGoTo = "confirm";
$errorGoTo = "error";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header("Location: ". $updateGoTo);
}else{
header("Location: ". $errorGoTo);
}
}
That worked for me. If anyone has a better way, please do provide. Someone else might just have this same problem and could benefit from our solutions.