dotj6816 2016-10-06 16:40
浏览 34
已采纳

使用Javascript重定向和显示警报

I can redirect to a new page but not invoke an alert.

On a click event on the submit button I want to get a JavaScript alert message and redirect to a page with some data updated.

The data update and redirection are working. The alert message is not being displayed.

I am aware that I have sql injection issue. I will work on it after I have the alert working.

<!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条回答 默认 最新

  • douba1904 2016-10-07 01:07
    关注

    It looks like you're defining a global function named "confirm", which will replace the existing window.confirm(). Inside your custom function, you then attempt call "window.confirm()" - BUT, since you replaced it, you are actually now calling your OWN function. This results in an infinite loop, causing...get ready for it...a "Stack Overflow" error :) Rename your function to something other than "confirm" (but continue to call window.confirm() inside of it, of course)

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 链接问题 C++LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型
  • ¥15 求学软件的前人们指明方向🥺
  • ¥50 如何增强飞上天的树莓派的热点信号强度,以使得笔记本可以在地面实现远程桌面连接