Page 1 of 1

MySQL Update not working

Posted: Wed Oct 25, 2006 3:39 pm
by tecktalkcm0391
How come this won't work ???

Code: Select all

$sql = mysql_query("UPDATE `basic` SET gender='($newgender)',month='($newmonth)',day='($newday)',year = '($newyear)' WHERE userid = '($userid)'");

Posted: Wed Oct 25, 2006 4:00 pm
by feyd
Swami says, the usage of parentheses around the variables.

Posted: Wed Oct 25, 2006 4:18 pm
by tecktalkcm0391
Ha ha ya, didn't relize that there suppost to be {} i feel stupid now
:oops:

Posted: Wed Oct 25, 2006 4:37 pm
by impulse()
I didn't realise there had to be any at all.

Somebody please point out to me if I'm wrong.

Posted: Wed Oct 25, 2006 5:01 pm
by volka
http://www.php.net/manual/en/language.t ... ng.complex
In fact, you can include any value that is in the namespace in strings with this syntax. You simply write the expression the same way as you would outside the string, and then include it in { and }.

Posted: Wed Oct 25, 2006 6:13 pm
by Cameri
I ran the following tests about including variables inside strings:

Code: Select all

//1st test
$mystr = "lala $myvar";
//2nd test
$mystr = "lala {$myvar}";
//3rd test
$mystr = "lala ".$myvar; //<-- faster
The tests were not exactly like this, of course I used more complex data than this.

And it turned out that the third test was faster than the other two.
The only downside that I see is that you have to type more, and if you don't have syntax highlighting it can become difficult to read. Don't use sprintf(), as you can do the same thing without it, and you save the overhead of the function call.

Choose what you think is best. Just my two cents.