目前,我非常疲惫,试图弄清楚为什么此功能无法按预期工作(在php类中):
function actualizarPromos($nombre,$desc,$motivo,$id){
global $mysqli;
$sql="update promociones set nombre='".utf8_decode($nombre)."', desc='".utf8_decode($desc)."', motivo='".$motivo."' where id='".$id."'";
$mysqli->query($sql);
if($mysqli->insert_id>0){
//It saved the data
echo "Salvado";
}
else{
//It didn't save the data
echo "No salvado";
echo $mysqli->insert_id;
echo "<br>".$sql;
}
}
我无法获得更新数据库内容的功能。我已经尝试在phpmyadmin上编写de SQL语句:
update promociones set nombre='cumple', desc='muy buen cumple', motivo='mCumple' where id='13';
而且它根本不执行。有人可以帮我吗?提前致谢!
最佳答案
desc
是MySQL中的Revered Word,因此您的查询很可能失败。您需要使用反引号将其转义-`
$sql="update promociones set nombre='".utf8_decode($nombre)."', `desc`='".utf8_decode($desc)."', motivo='".$motivo."' where id='".$id."'";