-2

I am getting the following mistake

Fatal error: Call to a member function query() on a non-object in C:\wamp\www\VisitBulgaria\register.php on line 25

when I run this code:

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();
        }
Dharman
  • 30,962
  • 25
  • 85
  • 135
user2567538
  • 15
  • 1
  • 1
  • 3

1 Answers1

0

You are mixing the mode of MySQLi usage. You are using direct function calls and then a object orientated way...

Have a look at this, this is how you do it using OO:

http://uk1.php.net/mysqli_query

Latheesan
  • 23,247
  • 32
  • 107
  • 201