Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: problem with updating my database...


Message #1 by "whip" <whip123@l...> on Mon, 3 Sep 2001 13:42:37
> incorrect syntax near '=',   

> SQLstmt = "UPDATE Students SET "
> SQLStmt = SQLstmt & "lastname='" & form_lastname & "',"	
> SQLstmt = SQLstmt & "firstname='" & form_firstname & "',"	
> SQLstmt = SQLstmt & "year='" & form_year & "'" 
> SQLstmt = SQLstmt & " WHERE ID=" & form_id 

If year is a numeric field, don't forget to leave out the ' ' marks.

Also note that if lastname is O'Reilly then you get

UPDATE Students SET lastname='O'Reilly', ...

which will give you a syntax error.  For this it's common to go

> SQLstmt = "UPDATE Students SET "
> SQLStmt = SQLstmt & "lastname='" & replace(form_lastname,"'","''") & "',"

> SQLstmt = SQLstmt & "firstname='" & replace(form_firstname,"'","''") &
"',"	
> SQLstmt = SQLstmt & "year='" & form_year & "'" 
> SQLstmt = SQLstmt & " WHERE ID=" & form_id 

The only other thing I can think of is the form_id is not numeric.

As richard says, to say much more, we need to see what the actual SQL is, so
straight after the above code, insert a response.write(SQLstmt) and let us
see the output!

Cheers,

Steve


  Return to Index