mysqli update函数删除表内容

时间:2017-05-25 14:42:00

标签: php mysqli

我对mysqli的编码很新,并且有一个我无法自己解决的问题:

我创建了一个插入,删除和更新页面。在数据库表中插入和删除新数据工作正常,但是当我尝试更新现有记录时,查询会以某种方式随机删除表格行中其他字段的内容。

我只使用了sql sql = "UPDATE xxx SET name='$name' WHERE id='$id";等。

我做错了什么?

2 个答案:

答案 0 :(得分:0)

您的SQL存在问题。

这:sql = "UPDATE xxx SET name='$name' WHERE id='$id"

应该是:sql = "UPDATE xxx SET name='$name' WHERE id = $id" <=== no quote before id

整数值不应该有引号。

要么是:sql = "UPDATE xxx SET name='$name' WHERE id = '$id'",如果你的id列不是整数

答案 1 :(得分:0)

您没有关闭WHERE子句中的单引号。 id是一个整数值,所以你根本不需要引号:
var $tr = $('#yourTable tr.no-sort'); //get the reference of row with the class no-sort var mySpecialRow = $tr.prop('outerHTML'); //get html code of tr $tr.remove(); //remove row of table $('#yourTable').dataTable({ "fnDrawCallback": function(){ //add the row with 'prepend' method: in the first children of TBODY $('#yourTable tbody').prepend(mySpecialRow); } });