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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with Update Set Where ID=#### 1

Status
Not open for further replies.

bjl6d

Programmer
Jul 28, 2006
5
US
Alright. I've been working on this all day with no results. I tried searching with no luck either.

I am using a form to update information in a row in the table. Basically the user enters in their Alumni ID (this is the primary key / auto_increment value) and the information that they want to change.

Here is the code I am trying to use:
$query = "UPDATE 'alumni' SET
'First_Name' = '$_POST[FName]',
'Last_Name' = '$_POST[LName]',
'Email' = '$_POST',
'Home_Street' = '$_POST[HAddress]',
'Home_City' = '$_POST[HCity]',
'Home_State' = '$_POST[HState]',
'Home_Zip' = '$_POST[HZip]',
'Home_Phone' = '$HomePhone',
'Cell_Phone' = '$CellPhone',
'Work_Name' = '$_POST[WName]',
'Work_Street' = '$_POST[WAddress]',
'Work_Street2' = '$_POST[WAddress2]',
'Work_City' = '$_POST[WCity]',
'Work_State' = '$_POST[WState]',
'Work_Zip' = '$_POST[WZip]',
'Work_Phone' = '$WorkPhone',
'Sector' = '$_POST[Sector]',
'Practice_Area' = '$_POST[Practice_Area]',
'Contact' = '$_POST[Contact]' WHERE 'ID' = $AlumniID LIMIT 1
";

$rs = mysql_query($query) or die("Something went awry");


When I run it, I keep getting the "Something went awry" message. I can't understand what's going on. I know for certain that the column rows and the values that are getting inputted are all correct (i.e. no typos). I think the problem is in the "WHERE 'ID' = $AlumniID" line, but I can't seem to fix it. ID is the name of the primary key column. Can anyone help me?
 
Hm. Well, I don't know why, but it works when I take out LIMIT 1 and the tick marks around each column heading.
 
the problem wasn't the LIMIT (which shouldn't be necessary)

the problem was that 'tickmarks' as you call them are not the same as `backticks`

`backticks` are permitted(*) to delimit column names, but 'tickmarks' or single quotes are used to delimit strings

and you cannot set strings to some other value ;-)

(*) but required if the column name is a reserved word or contains a special character like a space

best practice is not need to use `backticks` ever

r937.com | rudy.ca
 
Thanks for the explanation - truly appreciated!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top