代码还可以,我想进行一些验证,说“电子邮件已经注册”和“你的密码不匹配” 这是注册的完整代码
<!DOCTYPE html>
<html>
<head>
<title>Index</title>
<link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
<script src="bootstrap/jquery-3.1.1.min.js"></script>
<script src="bootstrap/js/bootstrap.min.js"></script>
</head>
<body>
<nav class="navbar navbar-inverse" style="border-radius:0px 0px 0px 0px;">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">JMK Sounds & Light</a>
</div>
<div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li><a href="index.php">Home</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Equipments <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="soundsys.php">Sound System</a></li>
<li><a href="lights.php">Lights</a></li>
</ul>
<li><a href="about.php">About</a></li>
<li><a href="contact.php">Contact Us</a></li>
</li>
</ul>
<div class="collapse navbar-collapse pull-right" id="bs-example-navbar-collapse-1">
<ul class="nav navbar-nav">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Sign in | Sign up <span class="caret" ></span></a>
<ul class="dropdown-menu" style="padding:5px;">
<li>
<div class="form-group">
<input type="text" class="form-control input-sm" placeholder="Username" style="margin-bottom:5px;" required/>
<input type="text" class="form-control input-sm" placeholder="Password" style="margin-bottom:5px;" required/>
<center><button class="btn btn-primary btn-sm">Sign in</button></center>
</div>
</li>
<center><button class="btn btn-primary btn-sm" data-toggle="modal" data-target="#signup">Sign Up</button></center>
<li>
<form class="navbar-form navbar-right" action="header.php" method="post">
</form>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<div class="modal fade" id="signup" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true"> × </span></button>
<h4 class="modal-title">Sign Up</h4>
</div>
<div class="modal-body">
<form action="save.php" method="post">
<div class="form-group">
<input type="text" name="fname" class="form-control input-sm" placeholder="First Name" required/><br />
<input type="text" name="sname" class="form-control input-sm" placeholder="Last Name" required/><br />
<center>
<input type="radio" name="gender" value="Male" required> Male
<input type="radio" name="gender" value="Female" required> Female<br /><br />
</center>
<input type="text" name="address" class="form-control input-sm" placeholder="Address" required/><br />
<input type="text" name="contact" class="form-control input-sm" placeholder="+639" required/><br />
<input type="text" name="email" class="form-control input-sm" placeholder="Email" required/><br />
<input type="text" name="uname" class="form-control input-sm" placeholder="Username" required/><br />
<input type="password" name="pword" class="form-control input-sm" placeholder="Password" required/><br />
<input type="password" name="cpword" class="form-control input-sm" placeholder="Confirm Password" required/><br />
<button type="button" class="btn btn-default btn-sm" data-dismiss="modal">Close</button>
<button type="submit" name="submit" class="btn btn-primary btn-sm">Submit</button>
</div>
</form>
</div>
</div>
</div>
</div>
答案 0 :(得分:1)
嗯,这样做实际上很简单。
您只需尝试连接数据库并在SQL中,使用提供的电子邮件搜索表。我在以下代码中使用了PDO扩展。
示例:
function Search_Customer($email)
{
global $db;
$query = "
SELECT customerID, CONCAT (firstName,' ', lastName) AS fullName,
city
FROM customers
WHERE email = :email";
$statement = $db->prepare($query);
$statement->bindValue(':email', $email);
$statement->execute();
$customer = $statement->fetchAll();
$statement->closeCursor();
return $customer;
}
然后当你调用方法时,检查返回的值是否为空(&#34;电子邮件不存在&#34;)或者是否有客户返回(&#34;电子邮件存在&#34;)。
当然也有密码,但同样的原则也适用于那里。
然后,您可以通过简单的&#34; echo&#34;显示响应消息。 /&#34; print&#34;或者更复杂的JavaScript代码
答案 1 :(得分:-1)
对于这种类型的验证,您可以使用php 这是您可以检查和修改的示例验证:
if ( isset($_POST['submit']) ) {
// clean user inputs to prevent sql injections
$name = trim($_POST['name']);
$name = strip_tags($name);
$name = htmlspecialchars($name);
$email = trim($_POST['email']);
$email = strip_tags($email);
$email = htmlspecialchars($email);
$pass = trim($_POST['pass']);
$pass = strip_tags($pass);
$pass = htmlspecialchars($pass);
// basic name validation
if (empty($name)) {
$error = true;
$nameError = "Please enter your full name.";
} else if (strlen($name) < 3) {
$error = true;
$nameError = "Name must have atleat 3 characters.";
} else if (!preg_match("/^[a-zA-Z ]+$/",$name)) {
$error = true;
$nameError = "Name must contain alphabets and space.";
}
//basic email validation
if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {
$error = true;
$emailError = "Please enter valid email address.";
} else {
// check email exist or not
$query = "SELECT userEmail FROM yourtable WHERE userEmail='$email'";
$result = mysql_query($query);
$count = mysql_num_rows($result);
if($count!=0){
$error = true;
$emailError = "Provided Email is already in use.";
}
}
// password validation
if (empty($pass)){
$error = true;
$passError = "Please enter password.";
} else if(strlen($pass) < 6) {
$error = true;
$passError = "Password must have atleast 6 characters.";
}
// password encrypt using SHA256();
$password = hash('sha256', $pass);
}