3

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` != '$terminado') = '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.

12
  • can you show what the $query variable contains? Commented Jun 22, 2011 at 17:59
  • Do you really need the ticks (`) around the column names in PHP? Commented Jun 22, 2011 at 18:01
  • @Dirk it is always best to use them Commented Jun 22, 2011 at 18:03
  • Try assigning the last statement to a variable; something like: $result = mysql_query($query) or die("Error ".mysql_error()); Commented Jun 22, 2011 at 18:05
  • @afaolek -- what would that do?? Commented Jun 22, 2011 at 18:07

2 Answers 2

1

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';";
Sign up to request clarification or add additional context in comments.

1 Comment

You don't need the parenthesis either.
0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.