i am new to this and i am stuck with this error
Undefined property: stdClass::$id in C:\xampp\htdocs\thesisApp\db\login.php on line 6
here is the code
<?php
$con = new mysqli("localhost", "root", "root", "thesisAppdb");
$data = json_decode(file_get_contents("php://input"));
$id = mysqli_real_escape_string($con, $data->id);
$username = mysqli_real_escape_string($con, $data->username);
$password = mysqli_real_escape_string($con, $data->password);
$query = ("SELECT id FROM teacherdata WHERE username= '$username' and
password= '$password' and id = '$id'");
$que = mysqli_query($con, $query);
$count = mysqli_num_rows($que);
if ($count == 1) {
echo 'correct';
} else {
echo 'wrong';
}
?>
hope to hear news from anyone.
As you can see from the output of var_dump
, that file_get_contents("php://input")
contains an empty json object
. Which when decoded provides an empty PHP object
. So, you need to make sure that there is id
key in the json object
and on the PHP side you can use the following:
$data = json_decode(file_get_contents("php://input"));
$id = 0;
if(isset($data->id))
{
$id = mysqli_real_escape_string($con, $data->id);
}