views:

37

answers:

1
$sql='UPDATE Reg_Stud SET Result=$perc WHERE RegID="$_SESSION['id']"';

Whts wrong with this syntax

+2  A: 

Two problems:

  • Variable interpolation does not happen in single quotes.
  • An un-escaped quote in a string prematurely terminates the string.

You can do:

$sql='UPDATE Reg_Stud SET Result='.$perc.' WHERE RegID='.$_SESSION['id'];
codaddict
You can do this, if you want Bobby Tables to screw your database.
delnan
@delnan: How do you know the variables are not sanitized?
codaddict
@delnen: I do not get? If you consider `$perc` (maybe it was `ctype_digit` checked?) and `$_SESSION['id']` (you set it yourself to an int) to be valid, then there is no chance Bobby Tables might attack. But obviously escaping them won't hurt you either ;)
nikic
I don't *know* the variables aren't sanitized, but come on, the odds are pretty good ;)
delnan
I had no idea who bobby tables was, im glad i know him now!
Drewdin
Your code does not yield in the same result.
Gumbo