問題

我在php中有一個指令碼.

 $id=$_GET['id'];
$endTime=$_GET['endTime'];

    $stmt = $con->prepare("SELECT candidateId from Attendence where candidateId=? and startTime>cast(? as time)");    //This is the problem line
    $stmt->bind_param("ds", $id,$endTime);

 //executing the query 
 $stmt->execute();


 //binding results to the query 
 $stmt->bind_result($var);

 $response = array(); 
 $response['success']=false;

 //traversing through all the result
 if($stmt->fetch())
 {

 $response['success']=true;
 $response['cand']=$var;
 }


 //displaying the result in json format 
 echo json_encode($response);
 

當我在url欄中輸入它時,這工作正常:

 http://arnabbanerjee.dx.am/checkAttendenceValidity.php?id=12100116050&endTime='14:30:00'
 

但是當我更改第3行時

 $stmt = $con->prepare("SELECT candidateId from Attendence where candidateId=? and startTime<cast(? as time)");
 

並輸入此網址:

 http://arnabbanerjee.dx.am/checkAttendenceValidity.php?id=12100116050&endTime='18:30:00'
 

它顯示{“成功”:false}

這是注意力表中的條目。

 12100116050(candidateId)  15:30:00(startTime)  2019-02-05   OS   present   17:30:00(endTime)
 

任何人都可以告訴我如何解決這個問題嗎?

  最佳答案

刪除endTime周圍的單引號

 http://arnabbanerjee.dx.am/checkAttendenceValidity.php?id=12100116050&endTime=18:30:00
 

否則查詢字串將擴充套件為:

 startTime<cast("'18:30:00'" as time)
 

轉換結果為 NULL。

  相同標籤的其他問題

phpmysql