0

I am not able to understand this error.

PHP error: Trying to get property of non-object

It is showing error in this line: if ($data->num_rows > 0)

I am new to php so I am having little difficulty to resolve this.

Source code :

<?php
if (isset($_GET["token"]) && isset($_GET["email"])) {
    $connection = new mysqli("localhost", "root", "", "hackathon");

    $email = $connection->real_escape_string($_GET["email"]);
    $token = $connection->real_escape_string($_GET["token"]);

    $data = $connection->query("SELECT id 
                                FROM registration 
                                WHERE email='$email' 
                                AND token='$token' 
                                AND token <> '' 
                                AND expire> NOW()");

    if ($data->num_rows > 0) { //   Error in this line
        $str = "0123456789qwertzuioplkjhgfdsayxcvbnm";
        $str = str_shuffle($str);
        $str = substr($str, 0, 15);

        $password = sha1($str);

        $connection->query("UPDATE registration SET password = '$password', token = '' WHERE email='$email'");

        echo "Your new password is: $str";
    } else {
        echo "Please check your link!";
    }
} else {
    header("Location: index.php");
    exit();
}
 ?>
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
rahul
  • 29
  • 5

0 Answers0