插入表单警报甜蜜不显示

时间:2017-07-16 04:28:41

标签: php

我想:

  1. 填写方框
  2. 按提交按钮
  3. 必填支票yesno
  4. 如果no,则显示提示甜蜜sweetAlert("Oops...", "Something went wrong!", "error");,如果yes显示提醒swal("Good job!", "You clicked the button!", "success")
  5. 在SQL中保存文字 - >重新加载主页
  6. 我的代码:

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

2 个答案:

答案 0 :(得分: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");
            }
        });
}
  1. 删除操作=&#34; index.php&#34;来自您的表格

答案 1 :(得分: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>