请问我在MySQL中存储JSON字符串有问题。 我需要存储这个:
{"image_intro":"images\/tips\/test.png","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}
但我在PHP中遇到错误:
PHP Parse error: syntax error, unexpected 'image_intro' (T_STRING) in /xxx/xxx/test.php on line 124
请问如何将字符串输入数据库?谢谢!
密码:
function setImage($image, $id) {
$tourId = $id;
$check = mysql_query("SELECT * FROM fm_content WHERE id_tour = '$tourId' LIMIT 1");
if(mysql_fetch_array($check) == true) {
mysql_query("UPDATE fm_content SET images = '{"image_intro":"images\/tipy\/velikonoce.png","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}' WHERE id_tour = '$tourId'");
}
}
答案 0 :(得分:3)
试试这个
function setImage($image, $id) {
$tourId = $id;
$check = mysql_query("SELECT * FROM fm_content WHERE id_tour = '$tourId' LIMIT 1");
if(mysql_fetch_array($check) == true) {
$data = '{"image_intro":"images\/tipy\/velikonoce.png","float_intro":"","image_intro_alt":"","image_intro_caption":"","image_fulltext":"","float_fulltext":"","image_fulltext_alt":"","image_fulltext_caption":""}';
mysql_query("UPDATE fm_content SET images = '{$data}' WHERE id_tour = '$tourId'");
}
}