我遇到以下错误(致命错误:在第25行的C:\ wamp \ www \ VisitBulgaria \ register.php中的非对象上调用成员函数query())当我运行此代码时:< / p>
Anu sugestions?
$username = mysqli_real_escape_string ($con,$_POST['Username']);
$password = mysqli_real_escape_string ($con,$_POST['Password']);
$forename = mysqli_real_escape_string($con,$_POST['Forename']);
$surname = mysqli_real_escape_string ($con,$_POST['Surname']);
$email = mysqli_real_escape_string ($con,$_POST['Email']);
$exists = 0;
$result = $mysqli->query("SELECT Username from customer WHERE Username = '{$username}' LIMIT 1");
if ($result->num_rows == 1) {
$exists = 1;
$result = $mysqli->query("SELECT Email from customer WHERE Email = '{$email}' LIMIT 1");
if ($result->num_rows == 1) $exists = 2;
} else {
$result = $mysqli->query("SELECT Email from customer WHERE Email = '{$email}' LIMIT 1");
if ($result->num_rows == 1) $exists = 3;
}
if ($exists == 1) echo "<p>Username already exists!</p>";
else if ($exists == 2) echo "<p>Username and Email already exists!</p>";
else if ($exists == 3) echo "<p>Email already exists!</p>";
else {
# insert data into mysql database
$sql = "INSERT INTO `customer` ( `Username`, `Password`, `Forename`, `Surname`, `Email`)
VALUES ( '{$username}', '{$password}', '{$foename}', '{$surname}', '{$email}')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "registered";
mysqli_close($con);
exit();
}
答案 0 :(得分:0)