0

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'");

}
?>
1
  • Whant does 'not working' means? Provide your error Commented Aug 8, 2011 at 10:01

2 Answers 2

1

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

Comments

0

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

2 Comments

Yeah, i know. Actually i took out the quotes just to get see whether any changes happens. But not changes. Now i tried again by adding quotes, its not working even now
you have a mysql connection set up? try this at the end: echo mysql_errno() . ": " . mysql_error() . "\n";

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.