MySQL Update not working

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

MySQL Update not working

Post 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)'");
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Swami says, the usage of parentheses around the variables.
User avatar
tecktalkcm0391
DevNet Resident
Posts: 1030
Joined: Fri May 26, 2006 9:25 am
Location: Florida

Post by tecktalkcm0391 »

Ha ha ya, didn't relize that there suppost to be {} i feel stupid now
:oops:
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

I didn't realise there had to be any at all.

Somebody please point out to me if I'm wrong.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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 }.
User avatar
Cameri
Forum Commoner
Posts: 87
Joined: Tue Apr 12, 2005 4:12 pm
Location: Santo Domingo, Dominican Republic

Post 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.
Post Reply