0

Right so i have php code to update a SQL table. If i replace $_GET['emailID'] with a number say 1 the database IS updated. But otherwise no update. What seems to be wrong here

Table: emails

Fields: mailbox, emailID

$query = 'UPDATE `emails` SET `mailbox`=\'trash\' WHERE `emailID`='.(int)$_GET['emailID'];
3
  • Do you get any errors from mysql? Can you print $query before you execute it? Commented Nov 25, 2013 at 10:07
  • May be the datatype in the table is int please check once Commented Nov 25, 2013 at 10:09
  • @Veerendra yes the data type is int in the table. But the transformation (int) is giving out as 0 if i print $query Commented Nov 25, 2013 at 10:51

4 Answers 4

1

Do like this

$query = "UPDATE `emails` SET `mailbox`='trash' WHERE `emailID`=".intval($_GET['emailID']);
Sign up to request clarification or add additional context in comments.

6 Comments

I am not sure. Doesn't (int) $var convert $var to int? php.net/language.types.type-juggling#language.types.typecasting
@user4035, Yeah it does. echo (int)$str='23test'; gives you 23.
@ShankarDamodaran So, his code must give the same result as yours. Frankly, I don't see any errors in this query except for missing parameter escaping. Maybe, the error is somewhere else?
@user4035, Right. @Haroon, What does this query give you on SQL , UPDATE emails SET mailbox='trash' WHERE emailID=1 ?
So my code now is $query = "UPDATE emails SET mailbox=\'trash\' WHERE emailID=".intval($_GET['emailID']); print $query; print "<b>".$_GET['emailID']."</b>"; Output: UPDATE emails SET mailbox='trash' WHERE emailID=0'1'
|
1

Can you try this,

 $query = 'UPDATE `emails` SET `mailbox`=\'trash\' WHERE `emailID`="'.(int)$_GET['emailID'].'" ';

3 Comments

print $query; print $_GET['emailID']; gives me ==> UPDATE emails SET mailbox='inbox' WHERE emailID="0"'2'
What is your Email id value ?
Can you post your complete url with query string?
0

Value of attribut must be selected by single quotes. Try this:

$query = "UPDATE `emails` SET `mailbox` = 'trash' WHERE `emailID` = '" . intval($_GET['emailID']) . "'";

Comments

0
$query = "UPDATE `emails` SET `mailbox`='trash' WHERE `emailID`= ".$_GET['emailID'];

Try this one sure it will work

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.