简体   繁体   English

如何使用爆破数组更新mysql

[英]How to UPDATE mysql using implode array

I am working on a form with multiple checkboxes. 我正在处理带有多个复选框的表单。 the value of checkboxes is stored in the mysql database and and INSERT query is working fine when i try to update record with UPDATE query something went wrong i have this index.php 复选框的值存储在mysql数据库中,并且当我尝试使用UPDATE查询更新记录时, INSERT查询工作正常,出现问题了,我有此index.php

This is my insert query which is working fine 这是我的插入查询,工作正常

$hobi=implode(',',$_POST['hobi']);

$db->query("INSERT INTO info (cekbox) VALUES('$hobi')");

And this is my update query which is not working means not updating records 这是我的更新查询,它不起作用意味着不更新记录

$hobi=implode(',',$_POST['hobi']);

//$db->query("INSERT INTO info (cekbox) VALUES('$hobi')");

$db->query("UPDATE info (cekbox) WHERE id= '$id' SET VALUES ('$hobi') ");

Please tell me how to put implode array in update query? 请告诉我如何将爆破数组放入更新查询中?

You got your update statement wrong. 您的更新声明有误。 This has nothing to do with the implode() . 这与implode()无关。

$db->query("UPDATE info SET cekbox='$hobi' WHERE id= '$id'");

不要将UPDATE查询视为INSERT查询

$db->query("UPDATE `info` SET `cekbox`='".$hobi."' WHERE `id`= $id"); 

your update sql is incorrect: 您的更新sql不正确:

UPDATE info (cekbox) WHERE id= '$id' SET VALUES ('$hobi')
// should be:
UPDATE info SET cekbox = '$hobi' WHERE id= '$id';

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM