the below code is not being executed
(edited)
<?php error_reporting(E_ALL); ini_set('display_errors', 1);
print "Hello world!";
$con = mysqli_connect($host,$uname,$pwd,$db) or die(mysqli_error());
$sql1="SELECT * FROM USERS WHERE username= 'aya'");
$result = mysqli_query($sql1);
if ($result && mysqli_num_rows($result) > 0) {
print "Hea!";
}
// json response array
$response = array("error" => FALSE);
$email = $_POST['username'];
$password = $_POST['password'];
$sql="SELECT * FROM USERS WHERE username= 'aya'";
if(mysqli_query($con,$sql))
{
echo json_encode($response);
}
?>
the error is here in this part because when I remove it , the link give results
$sql="SELECT * FROM USERS WHERE username= 'aya'") or die(mysqli_error())";
$result = mysqli_query($sql);
if ($result && mysqli_num_rows($result) > 0) {
print "Hea!";
}
The code in question has an obvious syntax and logical errors.
Correct your code as shown below:
...
// stop script execution with error message if db connection fails
$con = mysqli_connect($host, $uname, $pwd, $db) or die(mysqli_error());
$sql1 = "SELECT * FROM USERS WHERE username= 'aya'";
$result = mysqli_query($sql1);
if ($result && mysqli_num_rows($result) > 0) {
print "Hea!";
}
...
As you said the error is in this part:
$sql="SELECT * FROM USERS WHERE username= 'aya'") or die(mysqli_error())";
As you can see at the end of th line you put ";
just remove the double quote "
. Also you need to add a (
just before the "SELECT
, so your code should be:
$sql= ("SELECT * FROM USERS WHERE username= 'aya'");
$result = mysqli_query($sql) or die(mysqli_error());
Corrected code:
$con = mysqli_connect($host,$uname,$pwd,$db);
$sql="SELECT * FROM USERS WHERE username='aya'";
$result = mysqli_query($sql) or die(mysqli_error());
if ($result && mysqli_num_rows($result) > 0) {
print "Hea!";
}
Its the extra double quote ' " ' end of the 1st line before the semicolon i removed it.
$sql="SELECT * FROM USERS WHERE username= 'aya'") or die(mysqli_error());
$result = mysqli_query($sql);
if ($result && mysqli_num_rows($result) > 0) {
print "Hea!";
}