我正在尝试在将用户详细信息发送到服务器之前确认我的密码字段。我曾尝试使用 jquery 和 php 来实现这一点,但我无法让它工作。我知道这应该相当简单,但它在不确认密码的情况下发送详细信息。
我的代码如下(为了清楚起见,我删除了一些 div)
<form onSubmit="return validate()" id="register" method="post" action="../script/sendUserDetails.php">
<p style=" font-size:1.8em; color:black;">Ready</p>
<p style=" font-size:1.4em; color:black;">Enter your details</p>
<label for="fname">First Name: </label><br/>
<input autofocus name="fname" type="text" id="fname"
class="textEntry" required placeholder="First Name"/><br />
<label for="lname">Last Name: </label><br/>
<input name="lname" type="text" id="lname" class="textEntry" required placeholder="Last Name"/><br />
<label for="email">Email: </label><br/>
<input name="email" type="email" id="emailR" class="textEntry" required placeholder="Email"/><br />
<p style="font-size:1.8em; color:black;">Steady</p>
<p style="font-size:1.4em; color:black;">And your address</p>
<label for="address1">Address1: </label><br/>
<input name="address1" type="text" id="address1" class="textEntry" required placeholder="Address"/><br />
<label for="address2">Address2: </label><br/>
<input name="address2" type="text" id="address2" class="textEntry" placeholder="Address" /><br />
<label for="town">Town: </label><br/>
<input name="town" type="text" id="town" class="textEntry" required placeholder="Town"/><br />
<label for="postcode">Post Code: </label><br/>
<input name="postcode" type="text" id="postcode" class="textEntry" required placeholder="Post Code"/>
<br />
<label for="phone">Phone: </label><br/>
<input name="phone" placeholder="Phone" type="text" id="phone" class="textEntry" required/><br />
<p style="font-size:1.8em; color:black;">Go</p>
<p style="font-size:1.4em; color:black; ">Now a password</p>
<label for="password">Password: </label><br/>
<input name="password" placeholder="Password" type="password" id="passwordR" class="passwordEntry"
required/><br />
<label for="confirm_password">Confirm Password: </label><br/>
<input name="confirm_password" placeholder="Password" type="password" id="confirm_password" class="passwordEntry"
required/><br />
<p ><input class="button-link" type="submit" id="cu" value="Create Account"/></p>
</form>
我的php代码是;
<?php
include("dbconnect.php");
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$town=$_POST['town'];
$postcode=$_POST['postcode'];
$phone=$_POST['phone'];
$email=$_POST['email'];
$password=$_POST['password'];
$query = "select email from members where email='$email'";
$link = mysql_query($query);
if (!$link) {
die('query error');
}
$num=mysql_num_rows($link);
if ($num>0){
die('email already exists'); //email already taken
}
$query = "insert into members (fname, lname, address1, address2, town, postcode, phone, email,
password) values('$fname','$lname','$address1','$address2','$town','$postcode','$phone',
'$email','$password')";
$link = @ mysql_query($query);
if (!$link) {
die('table write error');
}
header("location:../members/members.master.php?page=regconfirm.php");
?>
以及我尝试使用的 jquery 代码(来自此站点);
function validate(){
if(!document.getElementById("Password").value==document.getElementById("confirm_password").value)alert("Passwords do no match");
return document.getElementById("Password").value==document.getElementById("confirm_password").value;
return false;
}
谢谢你的帮助。