help with MySQL update query

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
azak
Forum Newbie
Posts: 2
Joined: Thu Aug 04, 2005 8:08 am

help with MySQL update query

Post by azak »

Hello,

I am trying to update a simple address book. Below is the query string

Code: Select all

$query = "update $db_name set
Work_Place = '$WorkPlace',
Work_State = '$WorkState',
Work_Country = '$WorkCountry',
Home_Phone = '$HomePhone',
Cell_Phone = '$CellPhone',
Other_Phone = '$OtherPhone',
Home_Address = '$HomeAddress',
Home_State = '$HomeState',
Home_Country = '$HomeCountry',
email = '$email',
webpage = '$webpage',
notes = '$notes'
Where Log_Name = '$key2' ";

when I print out the query there are no single quotes around the Key in that (following is the query that is passed to MySQL)

Code: Select all

update contactlist set Work_Place = 'Some name', Work_State = 'DC', Work_Country = 'US', Home_Phone = '', Cell_Phone = '', Other_Phone = '', Home_Address = 'some address', Home_State = 'DE', Home_Country = 'US', email = '', webpage = '', notes = '' Where Log_Name = 'DAGH
The second single quote which encloses DAGH is missing. I cant seem to figure out what is wrong with the query. ANy help is appreciated.

Thanks
Azak


feyd | Please use

Code: Select all

tags in the future to post php code.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it looks like you have something run over the string after you finish creating it..
ckuipers
Forum Commoner
Posts: 61
Joined: Mon Mar 24, 2003 6:10 am

Post by ckuipers »

I wouldn't use variables in single quotes like this, try doing it like this:
Work_Place = '${WorkPlace}'
azak
Forum Newbie
Posts: 2
Joined: Thu Aug 04, 2005 8:08 am

Post by azak »

Thanks for the replies. Even with the curlybrackets on the query produces the same result.
I am printing the query right after I created the string with

Code: Select all

echo "<p>$query";
for debugging purposes which prints the query string.

It is being passed to

Code: Select all

mysql_query($query) or die(mysql_error());
which does not give me any error even though the mysql database is not being updated.

Any help is appreciated. Thanks

Nikhil

Ps: sorry about not having enclosed the php code in the earlier post. newbie error.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try seeing what mysql_affected_rows() says..
Post Reply