2017-07-16 97 views
0

我想:插入表格警报甜不显示

  1. 填写框
  2. 按提交按钮
  3. 要求检查yesno
  4. 如果no,显示警报甜sweetAlert("Oops...", "Something went wrong!", "error"); ,如果yes显示警报swal("Good job!", "You clicked the button!", "success")
  5. 将文本保存为SQL - >重新加载主页

我的代码:

<!DOCTYPE html> 
<html> 
<head> 
    <meta charset="utf-8"> 
    <title>alert sweet send form</title> 
    <script src="sweetalert.min.js"></script> 
<link rel="stylesheet" type="text/css" href="sweetalert.css"> 
</head> 
<body> 
<input type="text" id="username" required placeholder="userName"> 
<br> 
<br> 
<input type="text" id="password" required placeholder="passWord"> 
<br> 
<br> 
<button onclick="validation();">Đăng nhập</button> 

<script src="sweetalert.min.js"></script> 
<script type="text/javascript"> 
function validation() { 
    var userName = document.getElementById('username').value; 
    var passWord = document.getElementById('password').value; 
    if ((username == userName) && (password == passWord)) { 
     swal({ 
      title: "Bạn Đăng Nhập Thành Công!", 
      timer: 4000, 
      showConfirmButton: false 
     }); 
    } else { 
     sweetAlert("Lỗi...", "Mật khẩu hoặc tài khoản không đúng!", "error"); 
    } 
} 
</script> 
</body> 
</html> 

回答

0

你函数必须是这样的

function validation() 
{ 
    var userName = document.getElementById('username').value; 
    var passWord = document.getElementById('password').value; 
    swal({ 
      title: "Are you sure?", 
      text: "your message", 
      type: "warning", 
      showCancelButton: true, 
      confirmButtonColor: "#DD6B55", 
      confirmButtonText: "Yes", 
      cancelButtonText: "No", 
      closeOnConfirm: false, 
      closeOnCancel: false 
     }, 
     function(isConfirm){ 
      if (isConfirm) { 
       swal("Good job!!", "You clicked the button!", "success"); 
       // place your code here 
      } else { 
       swal("Oops...", "Something went wrong!", "error"); 
      } 
     }); 
} 
  • 删除操作= “的index.php” 从形式
  • +0

    谢谢你的帮助。我仍然无法按照上述规则使它工作 –

    +0

    我不理解你! – knizer

    +0

    谁会检查3 /需要检查是或否? – knizer

    0
    <?php 
    //ket nối 
        include 'database.php'; 
    //Hiển thị 
    
    
    
         if(isset($_POST['save'])){ 
         $id= $_POST['id']; 
         $username= $_POST['username']; 
         $password= $_POST['password']; 
    
    
    
    $sql="insert into `members`(id,username,password) Values ('$id','$username','$password')"; 
        // mysql_query("SET NAMES 'UTF8'"); 
    
    
    
        $pdo->exec($sql); 
    //echo '<script type="text/javascript">alert("Xin chúc mừng, tài khoản được tạo thành công !");window.location ="http://localhost/"; </script>'; 
    
    
    
    
    
             } 
    
    ?> 
    <!DOCTYPE html> 
    <html> 
    <head> 
        <meta charset="utf-8"> 
        <title>alert sweet send form</title> 
        <script src="sweetalert.min.js"></script> 
    <link rel="stylesheet" type="text/css" href="sweetalert.css"> 
    </head> 
    <body> 
    <form action="index.php" method="post"> 
    <input type="text" id="username" name="username" required placeholder="userName"> 
    <br> 
    <br> 
    <input type="text" id="password" name="password" required placeholder="passWord"> 
    <br> 
    <br> 
    <button onclick="validation();" name="save">Đăng nhập</button> 
    </form> 
        <script src="sweetalert.min.js"></script> 
    <script type="text/javascript"> 
        function validation() 
    { 
        var userName = document.getElementById('username').value; 
        var passWord = document.getElementById('password').value; 
        swal({ 
          title: "Are you sure?", 
          text: "your message", 
          type: "warning", 
          showCancelButton: true, 
          confirmButtonColor: "#DD6B55", 
          confirmButtonText: "Yes", 
          cancelButtonText: "No", 
          closeOnConfirm: false, 
          closeOnCancel: false 
         }, 
         function(isConfirm){ 
          if (isConfirm) { 
           swal("Good job!!", "You clicked the button!", "success"); 
           // place your code here 
          } else { 
           swal("Oops...", "Something went wrong!", "error"); 
          } 
         }); 
    } 
    </script> 
    </body> 
    </html>