<?php
$con=mysqli_connect("localhost","root","","db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$name = mysqli_real_escape_string($con, $_POST['name']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$phoneno = mysqli_real_escape_string($con, $_POST['phoneno']);
$status = mysqli_real_escape_string($con, $_POST['status']);
$sql = "SELECT * FROM register WHERE email='".$email."' AND status='1'";
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0)
{
$errormsg="email already exist";
}
else{
$sql="INSERT INTO register (name,email,password,phoneno,status) VALUES ('$name','$email','$password','$phoneno','1')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
exit;
mysqli_close($con);
}
?>
<form role="form" action="" autocomplete="off" method="POST">
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="name" class="form-control" name="name" placeholder="Company Name" required>
</div>
<span class="help-block"></span>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="email" class="form-control" name="email" placeholder="email address" required>
</div>
<?php echo $errormsg;?></span>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-lock"></i></span>
<input type="password" class="form-control" name="password" placeholder="Password" required>
</div>
<span class="help-block"></span>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-user"></i></span>
<input type="tel" id="tel" class="form-control" name="phoneno" pattern="\d{10}" placeholder="Please enter a ten digit phone number" required />
</div>
<span class="help-block"></span>
<input class="form-control" value="" type="hidden" name="status">
<button class="btn btn-lg btn-primary btn-block" name="submit" type="submit">Sign Up</button>
</form>
您想要在提交後顯示哪條消息? – Mad
@Macro檢查我的答案,您的代碼中的邏輯錯誤 – Developer
我試過了。但是隨着代碼的出現,消息將會每隔三秒刷新一次。 – Marco