mysql 这个语句有问题吗 大神帮看看 修改不了数据

$updata_sql="updata carinfo set type='$type',color='$color',country='$country',displacement='$displacement',config='$config',portdate='$portdate',sellprice='$sellprice',location='$location',complete='$complete',custom='$custom',customphone='$customphone',selldate='$selldate',note='$note' where vin='$vin'";
echo $updata_sql;
$updata_result=mysqli_query($conn,$updata_sql);
if(mysqli_affected_rows($conn)!=0)
			{echo $vin;}

这是echo的结果:updata carinfo set type='路虎揽胜',color='黑',country='加拿大',displacement='3.00',config='选装:豪华包、科技包、AMG运动包、智能驾驶辅助包(雷测)、电吸门、AMG 21寸轮毂、四季轮胎、橡木内饰、冷热杯架、铝制踏板、115V电源。 此车比中规GLE450豪华版88.98万的配置多:电吸门、抬头显示14000元、几何多光束大灯11500元、后排座椅加热、冷热杯架、21英寸轮毂 豪华包(Burmester环绕立体声系统,全景天窗,脚感电尾门,无钥匙进入和一键启动 前座快速加热功能,加热前扶手和上门板加热功能,第二排座椅加热,主动停车辅助 ) 运动包(AMG运动套件、AMG运动刹车系统,AMG 20寸双五幅轮毂) 科技包(抬头显示,360度环车影像,几何多光束LED大灯,自适应远光辅助系统) 智能驾驶包(雷达测距,自适应巡航,方向盘主动转向助力,自动防撞,主动盲点监测,车道保持辅助,预警制动,带交叉车流辅助功能的增强型制动辅助系统)',portdate='2020-05-21',sellprice='0.00',location='天津',complete='0',custom='',customphone='',selldate='1900-01-01',note='' where vin='241754'241754

图中的地方有问题:

修改是 update,不是updata

where条件需要指定具体字段

$updata_sql="updata carinfo set note='$note' where vin = (select vin from carinfo where vin='$vin')";

或者

$updata_sql="updata carinfo set note='$note' where vin in (select vin from carinfo where vin='$vin')";

$conn=mysqli_connect("localhost","root","root", "car") or die("数据库连接错误".mysql_error());

mysqli_query($conn, "set names utf8");

$updata_sql="updata carinfo set type='$type',color='$color',country='$country',displacement='$displacement',config='$config',portdate='$portdate',sellprice='$sellprice',location='$location',complete='$complete',custom='$custom',customphone='$customphone',selldate='$selldate',note='$note' where where vin='$vin' ";

$updata_result=mysqli_query($conn,$updata_sql);

if(mysqli_affected_rows($conn)!=0)

echo json_encode($vin);

where条件出错了where (select * from carinfo where vin='$vin'),修改为where vin='$vin';

mysql有updata的语法吗?    oracle好像是只有update,mysql不太清楚

最大的错误,update写错了。。。

 

updata===》update。。。。

 

除了where(select * from carinfo where vin='$vin')改为 where vin='$vin'

还得注意变量的内容,你那样是直接拼接sql语句,要注意将变量内容中的单引号替换为实体字符',要不你的sql语句会出错,有SQL注入漏洞。

你打印SQL语句出来看就知道了,目测肯定sql语句有错误。

echo $updata_sql;

防止SQL注入问题最好的办法是参数化,看下面的

https://blog.csdn.net/weixin_42405503/article/details/113473543