0

this is my php codes getting Post Successfully response when true but when it failed for some reason. i got this error.

mysqli_error() expects parameter 1 to be mysqli, null given

$result = mysqli_query($connection, $query) ;
    if($result){$response["msg"] = "Post Successfully";
echo json_encode($response);} else {$response["msg"] = "failed ".mysqli_error($con);
echo json_encode($response);
    }
    mysqli_close($connection);
}
devpro
  • 16,184
  • 3
  • 27
  • 38

2 Answers2

1

$con is null

mysqli_error($con); should be mysqli_error($connection); as you have declared connection as $connection.

Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78
1

According to this line:

mysqli_query($connection, $query)

You are using variable $connection for link identifier, and in mysqli_error($con) you are using $con variable which is undefined or NULL, this should be:

mysqli_error($connection)
devpro
  • 16,184
  • 3
  • 27
  • 38