【发布时间】:2015-08-02 09:06:00
【问题描述】:
我的服务器上有一个简单的 MySQL 表,有 4 个字段。 pid、aid、uname 和 active。我通过我的 android 应用程序将 uname 变量发送到我的 PHP 代码,我想将布尔值 active 列从 1 更改为 0,其中 uname 字段等于我通过应用程序发送的值。这是我的代码:
我从 android 应用程序发送的值在 index.php 中像这样接收并传递到 DB_Functions.php 中的另一个函数
else if ($tag == 'notpart'){
$uname = $_POST['uname'];
$notpart = $db->notpart($uname);
if (!empty($notpart)) {
// stored successfully
$response["success"] = 1;
//$response["notpart"]["aid"] = $notpart["aid"];
$response["notpart"]["uname"] = $notpart["uname"];
echo json_encode($response);
}
else {
// failed to store
$response["error"] = 1;
//$response["error_msg"] = "JSON Error occured";
$response["error_msg"] = mysql_error();
echo json_encode($response);
}
}
DB_Functions.php 中的函数:
更新: 将 $uname 更改为 '$uname'。现在 IllegalStringOffset 警告消失了,但 JSONException 存在
public function notpart($uname) {
$uuid = uniqid('', true);
echo $uname;
$result = mysql_query("UPDATE part SET active='0' WHERE uname = $uname");
// check for successful store
if ($result) {
//get event details
$pid = mysql_insert_id(); // last inserted id
$result = mysql_query("SELECT * FROM part WHERE pid = $pid");
//return event details
return mysql_fetch_array($result);
} else {
return mysql_error();
}
}
但是我收到了非法字符串偏移警告,并且没有对 MySQL 表进行任何更改。
这是日志:
05-20 21:57:26.958: E/JSON(17919): wwwww<br />n<b>Warning</b>: Illegal string offset 'uname' in <b>C:\xampp\htdocs\shareity\shareity\index.php</b> on line <b>445</b><br />n{"tag":"notpart","success":1,"error":0,"notpart":{"uname":"U"}}n
05-20 21:57:26.958: E/JSON Parser(17919): Error parsing data org.json.JSONException: Value wwwww<br of type java.lang.String cannot be converted to JSONObject
我尝试了isset 和!empty 方法来尝试发送非法偏移错误,但没有任何效果。有人可以告诉我有什么问题吗?谢谢
【问题讨论】:
标签: php android mysql json sql-update