简体   繁体   English

此更新查询出了什么问题?

[英]What's wrong with this update query?

I'm trying to make a form in a website where you can write the name, price or image of the product you want to update and in the textbox next to every field you can write the new value you want it to take but idk why everytime I write something the only field that updates is the name and instead of change the former name for the new one it change to 0, the php code I'm using is this: 我正在尝试在网站上制作一个表格,在其中您可以输入要更新的产品的名称,价格或图像,并在每个字段旁边的文本框中输入可以采用的新值,但idk为什么每次我写东西时,唯一更新的字段是名称,而不是将新名称更改为0,而不是更改以前的名称,而是使用以下php代码:

<?php

mysql_connect("localhost","paradise_root","gantzminus1");
mysql_select_db("paradise_dbsalon");
$nombre = $_POST['txtnombre']; 
$precio = $_POST['txtprecio'];  
$imagen = $_POST['txtimagen'];
$nombre2 = $_POST['txtnombre2']; 
$precio2 = $_POST['txtprecio2'];  
$imagen2 = $_POST['txtimagen2'];

$_GUARDAR_SQL = "update productosyservicios set nombre = ('".$nombre2."') or precio = ('".$precio2."') or imagen = ('".$imagen2."') where nombre = ('".$nombre."') or precio= ('".$precio."') or imagen = ('".$imagen."') "; 

$rst = mysql_query($_GUARDAR_SQL) or die("error".$_GUARDAR_SQL); 
if($rst==true){
$rest=false;

}
?>
$_GUARDAR_SQL = "update productosyservicios set nombre = ('".$nombre2."'), precio = ('".$precio2."'), imagen = ('".$imagen2."') where nombre = ('".$nombre."') or precio= ('".$precio."') or imagen = ('".$imagen."') "; 

You had or in your UPDATE 您在or更新中

(UPDATE productosyservicios set nombre = something **OR** <- this shouldnt be or it should be a comma

updates should be seperated by commas 更新应以逗号分隔

您的查询已关闭。

$_GUARDAR_SQL = "UPDATE productosyservicios SET nombre = '".$nombre2."', precio = '".$precio2."', imagen = '".$imagen2."' WHERE nombre = '".$nombre."' OR precio = '".$precio."' OR imagen = '".$imagen."'"; 

Your SQL query is very bad (not correct). 您的SQL查询非常糟糕(不正确)。

You must change to: 您必须更改为:

$_GUARDAR_SQL = "update productosyservicios set nombre = '".$nombre2."' , precio = '".$precio2."' , imagen = '".$imagen2."' where nombre = '".$nombre."' or precio= '".$precio."' or imagen = '".$imagen."' "; 

I'm not sure for your where clauses. 我不确定您的where子句。

Also check your database. 还要检查您的数据库。 Somewhere you can have integer column for text - change to varchar for all texts. 在某些地方您可以使用整数列作为文本-将所有文本更改为varchar。

this gona be with multiple CASE : 这个gona具有多个CASE:

Try that: 试试看:

UPDATE productosyservicios SET 
nombre = CASE WHEN nombre = '".$nombre."' then '".$nombre2."' else nombre   END ,
precio = CASE WHEN precio = '".$precio."' then '".$precio2."' else precio   END ,
imagen = CASE WHEN imagen = '".$imagen."' then '".$imagen2."' else imagen   END

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

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