使用Javascript重定向和显示警报

时间:2016-10-06 16:40:01

标签: javascript php

我可以重定向到新页面但不会调用警报。

在提交按钮上的click事件中,我想获取JavaScript警报消息并重定向到更新了一些数据的页面。

数据更新和重定向正常。警报消息未显示。

我知道我有sql注入问题。在我发出警报后,我会继续努力。

<!DOCTYPE html>

<?php

ob_start();
?>

<html>
<head>
    <title>Multiple Update and Delete Data</title>
    <?php include "header.php"; ?>
</head>

<body bgcolor="#DCE3E7">

<script type="text/javascript">
    function confirm() {
        if (window.confirm('Are you sure you want to update these properties?'))
        {
            window.alert("Successfully update.");
            document.location.href ='list_sale_update.php';
            return true;
        }
        else
        {
            alert("Error editing list. Please contact system administrator.");
            return false;
        }

    }
</script>

    <center><h1><font size="5" face="verdana" >Listing Modification</font></h1></center>


    <?php
    $conn = oci_connect("username","password","database")
    or die("Couldn't logon.");

            if (empty($_POST["check"]))
            {
                $query = "SELECT P.PTY_ID, P.PTY_UNITNUM, P.PTY_STREET,P.PTY_POSTCODE, P.PTY_SUBURB, P.PTY_CITY, T.P_TYPE_NAME,
                      L.LIST_PRICE, L.SALE_PRICE,
                      C.SELLER_FNAME, C.SELLER_LNAME, 
                      L.AVAILABILITY
              FROM    PROPERTY_TYPE T, PROPERTY P, CUSTOMER C, LISTINGS L  
              WHERE  P.P_TYPE_ID = T.P_TYPE_ID(+)
              AND    L.SELLER_ID = C.SELLER_ID(+)
              AND    P.PTY_ID = L.PTY_ID(+)
              ORDER BY P.PTY_ID";

                $stmt = oci_parse($conn,$query);
                oci_execute($stmt);
                ?>

                <form method="post"
                      action="list_avai_update.php">
                    <table border="2" cellpadding="5" align="center">
                        <tr>
                            <th><b> Property ID</th>
                            <th><b> Address</th>
                            <th><b> Property Type</th>
                            <th><b> Seller Name</th>
                            <th><b> Available?</th>
                            <th><b> Listing Price</th>
                            <th><b> Sale Price</th>
                            <th><b> Checkbox</th>
                        </tr>


                        <?php
                        while ($row = oci_fetch_array($stmt)) {
                            ?>
                            <tr>

                                <td><?php echo oci_result($stmt, "PTY_ID"); ?></td>

                                <td><?php echo oci_result($stmt, "PTY_UNITNUM"), " ", oci_result($stmt, "PTY_STREET"),
                                    ", ", oci_result($stmt, "PTY_SUBURB"), ", ", oci_result($stmt, "PTY_CITY"),
                                    ", ", oci_result($stmt, "PTY_POSTCODE"); ?></td>

                                <td><?php echo oci_result($stmt, "P_TYPE_NAME"); ?></td>
                                <td><?php echo oci_result($stmt, "SELLER_FNAME"), " ", oci_result($stmt, "SELLER_LNAME"); ?></td>

                                <td>
                                    Yes<input type="radio" name = "<?php echo oci_result($stmt, "PTY_ID"); ?>"
                                              value="1"<?php echo (oci_result($stmt, "AVAILABILITY") == '1') ? 'checked' : '' ?>><br>
                                    No <input type="radio" name = "<?php echo oci_result($stmt, "PTY_ID"); ?>"
                                              value="0"<?php echo (oci_result($stmt, "AVAILABILITY") == '0') ? 'checked' : '' ?>>
                                </td>

                                <td><?php echo oci_result($stmt, "LIST_PRICE"); ?></td>
                                <td><?php echo oci_result($stmt, "SALE_PRICE"); ?></td>

                                <td align="center">
                                    <input type="checkbox" name="check[]"
                                           value="<?php echo oci_result($stmt, "PTY_ID"); ?>">
                                </td>

                            </tr>
                            <?php
                        }
                        ?>
                    </table>
                <br><br>

                    <center>
                        <td><input type="submit" style="height:50px; width:200px" value="Confirm Update"
                                   onclick="return(confirm());"></td>                  &nbsp;&nbsp; &nbsp;
                        <input type="button" style="height:50px; width:200px" value="Return"
                                   OnClick="window.location='listing_multi.php'">
                    </center>

                </form>
                <?php
                oci_free_statement($stmt);
            }
            else
            {
                foreach ($_POST["check"] as $pty_id)
                {
                    $query = "UPDATE LISTINGS 
                      set AVAILABILITY = " . $_POST[$pty_id] . " 
                      WHERE PTY_ID ='" . $pty_id . "'";
                    $stmt = oci_parse($conn, $query);
                    oci_execute($stmt);
                    header("location: list_avai_update.php");


                }

            }

    oci_close($conn);
    ?>

<br><br>
<?php

$filename=$_SERVER["SCRIPT_FILENAME"];

?>
<a href="displaysource.php?filename=<?php echo $filename;?>" target="_blank"><img src="images/client.png "/> </a>


</body>
</html>

1 个答案:

答案 0 :(得分:0)

看起来你正在定义一个名为“confirm”的全局函数,它将取代现有的window.confirm()。在你的自定义函数中,你然后尝试调用“window.confirm()” - 但是,因为你替换它,你实际上现在正在调用你的OWN函数。这会导致无限循环,导致...为它做好准备...“堆栈溢出”错误:)将您的函数重命名为“确认”以外的其他内容(但继续在其中调用window.confirm(),当然)