提交后成功/失败消息弹出框? [英] successful/fail message pop up box after submit?

查看:140
本文介绍了提交后成功/失败消息弹出框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上单击提交按钮后,我想弹出一个弹出框说成功或失败,然后单击确定以确认消息。目前我得到一个弹出框未定义,然后是失败的消息弹出框。 请帮忙!

Basically after clicking the submit button, I want a pop up box to pop up saying successful or fail, then clicking OK to confirm the message. At the moment i am getting a pop up box "undefined" followed by failed message pop up box. HELP PLEASE!

这里是脚本

<?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标签之外。
把你的回声放在那里,你应该没事。

You are echoing outside the body tag of your HTML. Put your echos there, and you should be fine.

另外,删除 onclick =alert()来自您的提交。这是您的第一个未定义消息的原因。

Also, remove the onclick="alert()" from your submit. This is the cause for your first undefined message.

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

这篇关于提交后成功/失败消息弹出框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆