当我提供已注册的同一封电子邮件时,为什么显示空白页已经 SORRY ...您已经是注册用户...
connect.php
<?php
$servername = "localhost";
$username = "root";
$password = "root";
$database ="dbpro";
$con = mysqli_connect($servername, $username, $password,$database);
// Function for passing query into database
function query($sql_query) {
global $servername;
global $username;
global $password;
global $database;
global $con;
// Check connection
if (!$con) {
die("Connection failed: " . mysqli_connect_error());
}
if ($res = mysqli_multi_query($con, $sql_query)) {
return $res;
} else {
return false;
}
mysqli_close($con);
}
// Function for getting Indian Standard Time
function ist_time() {
date_default_timezone_set('Asia/Kolkata');
$time_now=mktime(date('h'),date('i'),date('s'));
$date = date('Y-m-d H:i:s', $time_now);
return $date;
}
?>
newuser.php
<?php
require'connect.php';
@$fname = mysqli_real_escape_string($con,$_POST['Fname']);
@$lname = mysqli_real_escape_string($con,$_POST['Lname']);
@$email = mysqli_real_escape_string($con,$_POST['Email']);
@$pass = mysqli_real_escape_string($con,$_POST['Password']);
@$gender = mysqli_real_escape_string($con,$_POST['Gender']);
@$country = mysqli_real_escape_string($con,$_POST['CountryCode']);
@$dob_d = mysqli_real_escape_string($con,$_POST['birthday_day']);
@$dob_m = mysqli_real_escape_string($con,$_POST['birthday_month']);
@$dob_y = mysqli_real_escape_string($con,$_POST['birthday_year']);
@$date_of_reg = ist_time();
$query = "INSERT INTO `CmUser` (`UserID`, `Fname`, `Lname`, `Email`, `Pass`, `Gender`, `Country`, `DOB_D`, `DOB_M`, `DOB_Y`, `Date_Of_Reg`) VALUES (NULL, '$fname', '$lname', '$email', '$pass', '$gender', '$country', $dob_d, $dob_m, $dob_y, '$date_of_reg');";
function NewUser() {
global $query;
$res = query($query);
if($res) {
echo "YOUR REGISTRATION IS COMPLETED..."; } else {
echo "Error in Regisrtation ".$res; }
}
function SignUp() {
global $con;
global $email;
global $pass;
if(!empty($email)) //checking the 'email' name which is from Sign-Up.html, is it empty or have some text
{
$result = mysqli_query($con,"SELECT * FROM CmUser WHERE Email = '$email';");
if(!$row = mysqli_fetch_array($result) or die(mysql_error())) {
newuser(); }
else { echo "SORRY...YOU ARE ALREADY REGISTERED USER..."; }
}
}
if(isset($_POST['submit'])) {
SignUp();
}
?>
我认为问题可能在这里:
$result = mysqli_query($con,"SELECT * FROM CmUser WHERE Email = '$email';");
if(!$row = mysqli_fetch_array($result) or die(mysql_error())) {
newuser(); }
else { echo "SORRY...YOU ARE ALREADY REGISTERED USER..."; }
答案 0 :(得分:1)
值$date_of_reg
必须位于查询中的单引号之间。此外,分号不是强制性的:
$query = "INSERT INTO `CmUser` (`UserID`, `Fname`, `Lname`, `Email`, `Pass`, `Gender`, `Country`, `DOB_D`, `DOB_M`, `DOB_Y`, `Date_Of_Reg`) VALUES (NULL, '$fname', '$lname', '$email', '$pass', '$gender', '$country', $dob_d, $dob_m, $dob_y, '$date_of_reg')";