在非对象上调用成员函数query()

时间:2014-04-16 11:28:59

标签: php

我遇到以下错误(致命错误:在第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();
        }

1 个答案:

答案 0 :(得分:0)

您正在混合使用MySQLi的模式。您正在使用直接函数调用,然后使用面向对象的方式......

看看这个,这就是你如何使用OO:

http://uk1.php.net/mysqli_query