开发者

update query not working (php, mysql)

开发者 https://www.devze.com 2023-03-14 14:19 出处:网络
I\'m trying to update information in my database but it is not updating and i\'m not getting any error. But when I execute the query with MySQL Query Browser it works and the information is updated co

I'm trying to update information in my database but it is not updating and i'm not getting any error. But when I execute the query with MySQL Query Browser it works and the information is updated correctly.

function cancelaDetalleOrden($id_orden,$id_pos,$id_componente)
{   
conectar();
$cancelado= "Cancelado";
$terminado= "Terminado";
echo $id_orden." ".$id_pos." ".$id_componente;//to check if data is retrieved
$query ="UPDATE procesos_orden 
             SET `status` = '$cancelado' 
             WHERE (`status` != '$te开发者_开发问答rminado') = '1' 
               AND `id_orden` = '$id_orden' 
               AND `id_posicion` = '$id_pos' 
               AND `id_componente` = '$id_componente';";
mysql_query($query)or die("Error ".mysql_error());
}

This is really weird because I have other functions where I update and they work well.


this looks like a bug

(`status` !=   '$terminado')= '1'  

without the =1 i suspect is what you wanted to do.

(`status` !=   '$terminado')

If it still doesn't work and it doesn'tgive an error, then you have a logical bug.

Here's how to fix it.

Run this query and see which records you are updating.

"SELECT * FROM procesos_orden 
 WHERE (`status` !=   '$terminado')= '1' 
   AND `id_orden` = '$orden' 
   AND `id_posicion` = '$id_pos' 
   AND `id_componente` = '$id_componente';";


Use this but see properly where I have used single quote, double quote, and tilde. Just change your variables with mine.

I have written values like this: '".$var."'

$up = mysql_query("UPDATE signup set `fname`='".$fn."',`lname`='".$ln."',`city`='".$ct."',`uname`='".$un."',`pass`='".$ps."',`eml`='".$ema."',`strm`='".$sm."',`add`='".$ad."' where `id`='".$uid."'") or die(" ".mysql_error());

This works 100% in my php page.

0

精彩评论

暂无评论...
验证码 换一张
取 消