bala
bala

Reputation: 1

Updating a table by using if condition - PHP - MySQL

Here am trying to update a field in a table with two values if the value which i got from other file using the GET function is Deactivate update the value of cnf_status as 1 and if it is Activate update the value of cnf_status as 0. But this bit of code is not working...can anyone help me how to solve this issue?

<?php
require_once '../config.php';
$id = $_GET['id'];
$status = $_GET['status'];


if($status == Deactivate)
{

mysql_query("update user_details set cnf_status='1' where user_id = '$id'");
}
else if($status == Activate)
{
mysql_query("update user_details set cnf_status='0' where user_id = '$id'");

}
?>

Upvotes: 0

Views: 510

Answers (2)

user409460
user409460

Reputation:

Usually you dont use Single quotes for Int fields... try removeing them. You only need them when using with fields like: text, varchar, enum

Also you should quote the Deactivate & Activate otherwise they will be used as constants

Upvotes: 0

JK.
JK.

Reputation: 5136

Forgot quotes maybe?

if($status == "Deactivate")
{
  mysql_query("update user_details set cnf_status='1' where user_id = '$id'");
}
else if($status == "Activate")
{
  mysql_query("update user_details set cnf_status='0' where user_id = '$id'");
}

You should also consider using mysql_real_escape_string() to avoid SQL Injections.

$id = mysql_real_escape_string($_GET['id']);

Upvotes: 1

Related Questions