tags:

views:

158

answers:

7

i have a field in table opt named confirm of type tinyint. i want to insert value(1) by this statement but it is not working can any one help??

$connect= mysql_connect("localhost","root") or die ("Sorry, Can not connect to database");

mysql_select_db("login") or die (mysql_error());

$user=$_POST['staff'];
echo $user;

$query="SELECT  * from users where username='$user' ";
$result=mysql_query($query,$connect) or die(mysql_error());
$row=mysql_fetch_array($result);

$uid=$row['userid'];
echo $uid;

$query="SELECT  * from opt where userid='$uid' ";
$result=mysql_query($query,$connect) or die(mysql_error());
$row=mysql_fetch_array($result);

if($row['confirm']==0)
{

$query = "INSERT INTO opt (confirm) values(1)";
echo 'The user selected options has confirmed';


}
?>
+8  A: 

You are not executing the query.

Bombe
Last query remains unexecuted
aivarsak
A: 

$query is a variable and there's no reason that it would cause a record to magically get inserted into the opt table.

You need to insert the following line after $query = "...":

mysql_query($query);

Also, I hopethat's not the code you're running in production.

You need to have the following somewhere:

$user = mysql_real_escape_string($user);
Allain Lalonde
+2  A: 

add an extra

$result=mysql_query($query,$connect) or die(mysql_error());

after the line

$query = "INSERT INTO opt (confirm) values(1)";

Jack
A: 

Apart from not executing the "InSERT STATEMENT",

You should probably be using an

 "UPDATE OPT SET CONFIRM = '1' WHERE USERID = $user;"

as the row already exists ('cause you managed to select it!).

James Anderson
A: 

now this is my update but not working

$query = "UPDATE opt SET confirm = 1 WHERE userid= $uid";

A: 

ok now its done thanks for all of u for helping me

make sure you mark one of the answers as the answer to the main question to help anyone else coming to this post.
localshred
A: 

Why is not working? what error is throwing?

Check the other fields of the table...

Ironicnet