Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在php表单中验证来自ajax的数据库的unque键,而不刷新表单内容_Php_Html - Fatal编程技术网

在php表单中验证来自ajax的数据库的unque键,而不刷新表单内容

在php表单中验证来自ajax的数据库的unque键,而不刷新表单内容,php,html,Php,Html,我试图显示一条确认手机已注册并重定向到同一表单的错误消息,而不刷新表单文本字段中输入的数据 我该怎么做 尝试此代码,关于手机上的验证,您应该将手机的主键设置为 应该是这样的 在这一页上有了想法,您应该查看它来了解ajax的模式 index.php <html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script&

我试图显示一条确认手机已注册并重定向到同一表单的错误消息,而不刷新表单文本字段中输入的数据

我该怎么做


尝试此代码,关于手机上的验证,您应该将手机的主键设置为

应该是这样的

在这一页上有了想法,您应该查看它来了解ajax的模式

index.php

<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>  
</head>
<body>
<div class="box-body">
<div class="form-group">
<label for="first-name">First Name</label>
<input type="text" class="form-control" id="first_name" name="first_name" placeholder="Enter First name" required="true">
</div>
<div class="form-group">
<label for="last-name">Last Name</label>
<input type="text" class="form-control" id="last_name"  name="last_name" placeholder="Enter Last Name" required="true">
</div>
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" name="email" placeholder="Enter email" required="true">
</div><div class="form-group">
<label for="phone">Contact</label>
<input type="number" class="form-control" id="phone" name="phone" placeholder="Enter contact no" required="true">
</div>
<div class="form-group">
<label for="address"> Address</label>
<input type="text" class="form-control" id="Address" name="address" placeholder="Enter Address" required="true">
</div>
<div class="box-footer">
<button type="submit" id="button" class="btn btn-primary">Submit</button>
</div>
<script>
        $(document).ready(function(){
            $("#button").click(function(){
                var first_name =$("#first_name").val();
                var last_name = $("#last_name").val();
                var email=$("#email").val();
                var phone=$("#phone").val();
                var Address=$("#Address").val();
                $.ajax({
                    url:'fetch.php',
                    method:'POST',
                    data:{
                        first_name:first_name,
                        last_name:last_name,
                        email:email,
                        phone:phone,
                        Address:Address
                    },
                   success:function(data){
                       alert(data);
                       document.location.href = "help.php";
                   }
                });
            });
        });
</script>
</body>
</html>

名字
姓
电子邮件地址
接触
地址
提交
$(文档).ready(函数(){
$(“#按钮”)。单击(函数(){
var first_name=$(“#first_name”).val();
var last_name=$(“#last_name”).val();
var email=$(“#email”).val();
var phone=$(“#phone”).val();
var Address=$(“#Address”).val();
$.ajax({
url:'fetch.php',
方法:'POST',
数据:{
名字:名字,
姓氏:姓氏,
电邮:电邮,,
电话:电话,,
地址:地址
},
成功:功能(数据){
警报(数据);
document.location.href=“help.php”;
}
});
});
});
fetch.php

<?php

$conn =new mysqli("localhost","root","","yourdatabase");
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$address = $_POST['Address'];

$user_query = "INSERT INTO `user`( `first_name`, `last_name`, `email`, `phone`,`address`)"
        . " VALUES ('$first_name','$last_name','$email','$phone','$address')";
if($conn->query($user_query ) === TRUE)
    {
        echo "Data Inserted";
    }
    else
    {
        echo "Contact Should be Unique";
    }


  ?>

对不起,我不是100%知道问题是什么。只是如何在不刷新的情况下发布表单数据?如果是,,那么你所需要做的就是使用ajax可能重复使用ajax我怎么做我几乎不知道ajax或javascript在重复输入phone之后,我想重定向到表单index.php,使用我输入的相同条目我能做什么that@Ayushsinghthakur我编辑了答案,只是把它复制出来。@Ayussinghthakur更改document.location.href=“fetch.php”插入此文档。location.href=“index.php”抱歉