2017-02-15 33 views
0

當我點擊API時,我以前動態獲取了結果。在此之前,我爲android創建了很多API,但我從來沒有像這樣面臨過問題。我被創建了一個API,從android獲取ID並將該ID的詳細信息發送給android

下面是代碼

<?php 
    error_reporting(0); 
    echo $empId = $_REQUEST['empId']; 
    date_default_timezone_set('Asia/Kolkata'); 
    $datetime = date('Y-m-d H:i:s'); 
    require_once "db.php"; 
    $query = "SELECT `id`, `name`, `mobileNumber`, `tempMobileNumber`,         `email`, `photo`, `supervisorId`, `emergencyMobileNumber`, `emergencyName`, `relation`, `address`, `designation`, `appId`, `qrCode`, `vendorId`, `siteName`, `latitude`, `langitude` FROM `tbl_employee` WHERE `appId`= $empId"; 
$result = mysqli_query($connect,$query); 
echo $count = $result->num_rows; 

if($count > 0) 
{ 
    $response["empDetails"] = array(); 
    $row_user = $result->fetch_assoc(); 

    $emp = array(); 
    $emp["ID"] = $row_user["id"]; 
    $emp["appId"] = $row_user["appId"]; 
    $emp["name"] = $row_user["name"]; 
    $emp["mobileNumber"] = $row_user["mobileNumber"]; 
    $emp["tempMobileNumber"] = $row_user["tempMobileNumber"]; 
    $emp["email"] = $row_user["email"]; 

    array_push($response["empDetails"], $emp); 
    $response["success"] = 1; 
    $response["message"] = "Attendance Placed Successfully."; 
    echo json_encode($response); 
} 
else 
{ 
    echo "wrong"; 
} 
?> 
+0

什麼是錯誤? – gaurav

+0

$ result = mysqli_query($ connect,$ query);結果得不到正確 –

+0

評論錯誤報告的行比看看你在代碼中得到了什麼錯誤 – gaurav

回答

1

你只需重寫查詢爲(替換這個現有查詢):

$query = "SELECT `id`, `name`, `mobileNumber`, `tempMobileNumber`, `email`, `photo`, `supervisorId`, `emergencyMobileNumber`, `emergencyName`, `relation`, `address`, `designation`, `appId`, 
    `qrCode`, `vendorId`, `siteName`, `latitude`, `langitude` FROM `tbl_employee` WHERE `appId`= '".$empId."'"; 

我想你已經在字符串附加語法錯誤。這可能會適用於你的情況。

還要檢查你在上面的問題連接數據庫正常

2

您的查詢是錯誤的,也斷行(;)缺少 更新查詢符合這個

$query = "SELECT * from table_name where your_id='$empId'; // you can add the column name which you want to retrieve. 

在你您的查詢行上方的代碼不正確。

相關問題