我想在jquery验证后将数据插入到我的数据库中。但是,提交按钮仅适用于验证,不会提交数据。请帮帮我谢谢〜
这是我的表单
<form id="myform" method="POST">
<label for="username">Username: </label>
<input type="text" class="left" id="username" name="username">
<label for="name">Name: </label>
<input type="text" class="left" id="name" name="name">
<label for="password">Password </label>
<input type="password" class="left" id="password" name="password">
<label for="repassword">Password </label>
<input type="password" class="left" id="repassword" name="repassword">
<label for="email">Email </label>
<input type="email" class="left" id="email" name="email">
<label for="contact">Contact</label>
<input type="text" class="contact" id="contact" name="contact">
<input id="submit" type="submit" name="submit" value="Send" />
</form>
这是我的jquery验证表单
<script>
$.validator.addMethod('contact', function (value, element) {
return this.optional(element) || /^\d{3}-\d{7}$/.test(value);
}, "Please enter a valid phone number");
jQuery.validator.addMethod( 'passwordMatch', function(value, element) {
// The two password inputs
var password = $("#password").val();
var confirmPassword = $("#repassword").val();
// Check for equality with the password inputs
if (password != confirmPassword ) {
return false;
} else {
return true;
}
}, "Your Passwords Must Match");
$(document).ready(function() {
$( "#myform" ).validate({
rules: {
debug:false,
username: {
required: true,
rangelength:[4,10],
// remote: "user_check2.php"
},
name: {
required: true,
rangelength:[4,10]
},
password: {
required: true,
rangelength:[6,10]
},
repassword: {
passwordMatch: true // set this on the field you're trying to match
},
email: {
required: true,
},
contact: {
required: true,
},
},
messages: {
username: {
//remote:"Username already existed",
required:"Enter your username",
},
name: {
required:"Please enter your name",
},
password: {
required:"Please enter your Password",
rangelength:"You must contain 6 to 10 character"
},
contact: {
required:"Please enter your phone number",
},
});
});
</script>
<?php
if(isset($_POST['submit']))
{
$adminusername = $_POST["username"];
$name = $_POST["name"];
$email = $_POST["email"];
$phone = $_POST["contact"];
$password = $_POST["password"];
//$query = "select * from admin where Admin_Username = '$adminusername'";
//$result = mysqli_query($conn,$query);
//$rowcount = mysqli_num_rows($result);
mysqli_query($conn,"Insert into admin(Admin_Username,Admin_Name,Admin_Email,Admin_Contact,Admin_Password) values
('$adminusername','$name','$email','$phone','$password')");
mysqli_close($conn);
}
?>
答案 0 :(得分:1)
我认为您错过了表单中的action
属性。
<form method="post" action="your_php_code.php">