Moudiz Moudiz - 6 months ago 9
PHP Question

php code doesn't give correct result

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!";
}

Answer

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!"; 
 }
...