Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

update syntax problem

Status
Not open for further replies.

gokeeffe

Programmer
Jan 11, 2005
170
IE
Greetings,

As you can see i'm an annoying newbie can anyone tell me

what is wrong with my code.

if ($j1 && $k1 && $l1 && $g1 && $h1 && $i1 && $a1)

{

// Insert Keys into table
$query = "UPDATE users SET contact_name = '$j1'
landline = '$k1'
mobile = '$l1'
county_id = '$g1'
town_region_name = '$h1'
extra_location_details = '$i1'
WHERE user_id = '$a1'";
$result = @mysql_query ($query); // Run the query

Tks in advance

Gaz
 
I forgot to insert the commas but it still doesn't work

if ($j1 && $k1 && $l1 && $g1 && $h1 && $i1 && $a1)

{

// Insert Keys into table
$query = "UPDATE users SET contact_name = '$j1',
landline = '$k1',
mobile = '$l1',
county_id = '$g1',
town_region_name = '$h1',
extra_location_details = '$i1',
WHERE user_id = '$a1'";
$result = @mysql_query ($query); // Run the query
 
If you print the SQL after you create it and before you run it, does it look correct? Does it run when you past it into a mysql shell? Does the code even get there, since you include the "if" statement surrounding it?
 
You'll need a comma after each field you are updating:

Code:
UPDATE users 
SET 
   contact_name = '$j1',
   landline     = '$k1',
   mobile       = '$l1',
   county_id     = '$g1',
   town_region_name = '$h1',
   extra_location_details = '$i1'
WHERE user_id  = '$a1'

Be certain that there are no single quotes embedded in any of these fields. For example, if extra_location_details turns out to be "Make a left after George's restaurant". You'll have a problem with your query. You'd need to code the string constant as "Make a left after George\'s restaurant" if I remember right.
 
Tks dalchri

I had a comma after the '$il'

It now works perfectly

Tks for your help

Slainte (Irish for see ya)
 
Oh, well in that case, may certain that no one enters a contact like "O'Brian" :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top