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

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 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!"; 
     }
    ...
    
    点赞 评论 复制链接分享
  • doudong4532 doudong4532 2016-05-21 20:49

    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());
    
    点赞 评论 复制链接分享
  • doubei3312 doubei3312 2016-05-21 20:50

    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!"; 
    }
    
    点赞 评论 复制链接分享
  • douxiangshi6568 douxiangshi6568 2016-05-21 20:51

    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!"; 
      }
    
    点赞 评论 复制链接分享

相关推荐