基本上点击提交按钮后,我想弹出一个弹出框,表示成功或失败,然后单击确定确认消息.目前我正在弹出一个弹出框“undefined”,然后是失败的消息弹出框.请帮助!
这是脚本
<?PHP include ('config.PHP'); if (isset($_POST['name'])) { $name = "name"; $query = "INSERT INTO pop ('id','name') VALUES ('','$name')"; $result = MysqL_query($query,$cn); if ($result) { echo "<script type='text/javascript'>alert('submitted successfully!')</script>"; } else { echo "<script type='text/javascript'>alert('Failed!')</script>"; } } ?> <html> <head> </head> <body> <form action="" method="post"> Name:<input type="text" id="name" name="name"/> <input type="submit" value="submit" name="submit" onclick="alert();"/> </form> </body>
你正在回应HTML的body标签之外.
把你的回声放在那里,你应该没事.
原文链接:https://www.f2er.com/php/132790.html把你的回声放在那里,你应该没事.
另外,从你的提交中删除onclick =“alert()”.这是您的第一个未定义的消息的原因.
<?PHP $posted = false; if( $_POST ) { $posted = true; // Database stuff here... // $result = MysqL_query( ... ) $result = $_POST['name'] == "danny"; // Dummy result } ?> <html> <head></head> <body> <?PHP if( $posted ) { if( $result ) echo "<script type='text/javascript'>alert('submitted successfully!')</script>"; else echo "<script type='text/javascript'>alert('Failed!')</script>"; } ?> <form action="" method="post"> Name:<input type="text" id="name" name="name"/> <input type="submit" value="submit" name="submit"/> </form> </body> </html>