doulipi3742 2016-05-21 20:40
浏览 46
已采纳

php代码没有给出正确的结果[关闭]

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!"; 
      }
  • 写回答

4条回答 默认 最新

  • dszpyf4859 2016-05-21 20:50
    关注

    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!"; 
     }
    ...
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?