2013-08-16 71 views
1

我的PHP返回值時,值傳遞給它我檢查了鉻的插件POSTMAN ...我無法找出問題:\ 這是我的代碼我試圖從我的Android代碼發送值(這是好的)來更新數據庫: -我的PHP返回值爲空時值傳遞給它

<?php 


$response = array(); 

// check for required fields 
if (isset($_POST['id']) && isset($_POST['company']) && isset($_POST['date']) && 
isset($_POST['time']) && isset($_POST['ten']) && isset($_POST['twelve']) &&  
isset($_POST['aggregate']) && isset($_POST['backlog']) && isset($_POST['pending']) &&   
isset($_POST['branch'])) { 
$cid = $_POST['id']; 
$company = $_POST['company']; 
$date = $_POST['date']; 
$time = $_POST['time']; 
$ten = $_POST['ten']; 
$twelve = $_POST['twelve']; 
$aggregate = $_POST['aggregate']; 
$backlog = $_POST['backlog']; 
$pending = $_POST['pending']; 
$branch = $_POST['branch']; 

// include db connect class 
require_once __DIR__ . '/db_connect.php'; 

// connecting to db 
$db = new DB_CONNECT(); 

// mysql update row with matched pid 
$result = mysql_query("UPDATE companies SET company = '$company', date = '$date', time 
= '$time' ten = '$ten', twelve = '$twelve',aggregate = '$aggregate', backlog = 
'$backlog', pending = '$pending', branch = '$branch' WHERE id = $cid"); 

// check if row inserted or not 
if ($result) { 
// successfully updated 
$response["success"] = 1; 
$response["message"] = "Company successfully updated."; 

// echoing JSON response 
echo json_encode($response); 
} else { 

} 
} else { 
// required field is missing 
$response["success"] = 0; 
$response["message"] = "Required field(s) is missing"; 

// echoing JSON response 
echo json_encode($response); 
} 
?> 
+0

'//連接到數據庫 $ DB =新DB_CONNECT();'這看起來很奇怪 –

+1

OOF。你需要使用準備好的語句。這是不安全的。請參閱[這裏](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php?rq=1) –

+0

請使用參數化查詢與PDO;你的代碼很容易發生SQL注入。 – mc10

回答

3

你錯過了一個逗號:

= '$time', ten = '$ten', twelve = '$twelve', aggregate = '$aggregate', backlog = 
    ____^_____ 
+0

傻我thnks man:D –

+0

如果這是解決您的問題,您應該接受答案,以便其他人可以看到解決方案 – Jake