【发布时间】:2020-12-31 20:51:22
【问题描述】:
我正在尝试更新 mysql DB 中的产品
这是我的产品表结构: 【表产品结构】
它有一个外键 id_category 引用表类别的 id : 【表类结构】
这是我的代码:
if(isset($_POST['submit'])){
$id=htmlspecialchars($_POST['id']);
$name=htmlspecialchars($_POST['name']);
$photo=htmlspecialchars($_POST['photo']);
$quantity=htmlspecialchars($_POST['quantity']);
$price=htmlspecialchars($_POST['price']);
$description=htmlspecialchars($_POST['description']);
$category=htmlspecialchars($_POST['category']);
$brand=htmlspecialchars($_POST['brand']);
$obj=new Connexion();
$cnx=$obj->getconnexion();
//sql statement
$sql="update product set id=$id,name='$name',photo='$photo',quantity=$quantity,price=$price,description='$description',category=(select id_category from category where category_name='$category'),brand='$brand' where id=1";
$res=$cnx->exec($sql);
if($res)
{ header("location:findall.html.php");}
else echo "modification problem!!";
当我尝试它时,它会说
修改问题!!
POST 方法工作正常,但我不知道 sql 语句中的错误在哪里。
【问题讨论】: