继承我在PHP中的代码,
见文字
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
include 'DatabaseConfig.php';
$con = mysqli_connect($HostName, $HostUser, $HostPass, $DatabaseName);
$Email = $_POST['User_Email'];
$Password = $_POST['User_Password'];
$Full_Name = $_POST['User_Full_Name'];
$CheckSQL = "SELECT * FROM register_account WHERE User_Email='$Email'";
$check = mysqli_fetch_array(mysqli_query($con, $CheckSQL));
if (isset($check))
{
echo 'Email Already Exist, Please Enter Another Email.';
}
else
{
$Sql_Query = "INSERT INTO register_account values(User_Email,User_Password,User_Full_Name) values ('$Email','$Password','$Full_Name')";
if (mysqli_query($con, $Sql_Query))
{
echo 'User Registration Successfully';
}
else
{
echo 'Something went wrong';
}
}
}
mysqli_close($con);
这是我尝试在浏览器上查看时的错误
Notice: Undefined variable: con in C:\xampp\htdocs\android\User-Registration.php on line 36
Warning: mysqli_close() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\android\User-Registration.php on line
我已经多次检查我的数据库和代码,但似乎仍然没有工作。有人可以帮帮我吗?谢谢!
答案 0 :(得分:1)
好吧,检查您的代码:如果mysqli_connect
请求发生,您只是在运行POST
,但在每个请求中都运行mysqli_close
答案 1 :(得分:0)
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
include 'DatabaseConfig.php';
$con = mysqli_connect($HostName, $HostUser, $HostPass, $DatabaseName);
$Email = $_POST['User_Email'];
$Password = $_POST['User_Password'];
$Full_Name = $_POST['User_Full_Name'];
$CheckSQL = "SELECT * FROM register_account WHERE
User_Email='$Email'";
$check = mysqli_fetch_array(mysqli_query($con, $CheckSQL));
if (isset($check)) {
echo 'Email Already Exist, Please Enter Another Email.';
} else {
$Sql_Query = "INSERT INTO register_account
values(User_Email,User_Password,User_Full_Name) values
('$Email','$Password','$Full_Name')";
if (mysqli_query($con, $Sql_Query)) {
echo 'User Registration Successfully';
} else {
echo 'Something went wrong';
}
}
mysqli_close($con);
}
?>