2013-08-16 45 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