I have the current issue, my php script is demanding on some JS code. It is declared in a PHP echo. But it seams like when its loading that all the "task" are triggered at once when the page is done loading.
So after the php is loaded in I get all the $messages popped-up when they are compliant. Example: At the last php alinea the status: "Goedgekeurd door klant" will be updated into the database. But I'll get the popup declared in the IF (first alinea) afterwards
I want the script to be functioning from top to bottom. (like the rest of php is doing)
Before any comments, yes I know this script is bad, and is open for Injection. But this is just a test scenario. In the real code, this is not the case.
Here is my code:
<?php
if($status == "Goedgekeurd door klant"){
$message = "Offerte $oid is reeds beantwoord met de status: Goedgekeurd door klant.";
echo "<script type='module'>alert('$message');
window.location.href = 'customer_quote.php?offerteid=$offerteid&comp=$comp&ikey=$ikey&fail=1';
</script>";
}
if($status == "Afgewezen door klant"){
$message = "Offerte $oid is reeds beantwoord met de status: Afgewezen door klant.";
echo "<script type='module'>alert('$message');
window.location.href = 'customer_quote.php?offerteid=$offerteid&comp=$comp&ikey=$ikey&fail=1';
</script>";
}
//getting customerid from url
$id = $_GET['id'];
$omschrijving = "$klantnaam heeft offerte $oid goedgekeurd.";
$date = date("d-m-Y G:i");
$link1 = "/modules/quotes/offerte.php?offerteid=$offerteid";
//Connect to DB
$companyname = $_GET['comp'];
include("$root/connections/customerdbconnection.php");
// Attempt insert query execution
$sql = "INSERT INTO notifications (klant, omschrijving, link, uid, createdat) VALUES ('$klantnaam', '$omschrijving', '$link1', '$oid', '$date')";
if(mysqli_query($link, $sql)){
echo "Notificatie gecreeerd!";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Attempt insert query execution
$sql = "UPDATE offertes SET status='Goedgekeurd door klant' WHERE offerteid=$offerteid";
if(mysqli_query($link, $sql)){
$message = "Dankuwel, offerte $oid is door u gemarkeerd als 'Goedgekeurd'.";
echo "<script type='module'>alert('$message');
window.location.href = 'customer_quote.php?offerteid=$offerteid&comp=$comp&ikey=$ikey&fail=1';
</script>";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>