Page 1 of 1

help with MySQL update query

Posted: Thu Aug 04, 2005 8:12 am
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]

Posted: Thu Aug 04, 2005 8:18 am
by feyd
it looks like you have something run over the string after you finish creating it..

Posted: Thu Aug 04, 2005 8:51 am
by ckuipers
I wouldn't use variables in single quotes like this, try doing it like this:
Work_Place = '${WorkPlace}'

Posted: Thu Aug 04, 2005 4:48 pm
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.

Posted: Thu Aug 04, 2005 5:53 pm
by feyd
try seeing what mysql_affected_rows() says..