简体   繁体   English

PHP 中的 JavaScript 回显序列不正确

[英]JavaScript in PHP echo sequence not right

I have the current issue, my php script is demanding on some JS code.我有当前的问题,我的 php 脚本需要一些 JS 代码。 It is declared in a PHP echo.它在 PHP 回显中声明。 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.因此,在加载 php 后,当它们符合要求时,我会弹出所有 $messages。 Example: At the last php alinea the status: "Goedgekeurd door klant" will be updated into the database.示例:在最后的 php alinea 中,状态:“Goedgekeurd door klant”将更新到数据库中。 But I'll get the popup declared in the IF (first alinea) afterwards但是之后我会在 IF(第一个 alinea)中声明弹出窗口

I want the script to be functioning from top to bottom.我希望脚本从上到下运行。 (like the rest of php is doing) (就像 php 的其余部分正在做的一样)

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);
?>

Fixed it by putting exit();通过放置exit();修复它exit(); at the end of the JS scripts.在 JS 脚本的末尾。

将此alert('$message')更改为该alert('".$message."')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM