Syntax error in UPDATE statement.

Hi guys, i’m having this error…

Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in UPDATE statement.
/alle_new/modifydata.asp, line 14

below is my codes:

<%

username = Request.Form("username")
password = Request.Form("password")
firstName = Request.Form("first")
lastName = Request.Form("last")
emailName = Request.Form("email")
	
str = "UPDATE user_details SET username = " & username & ", password = " & password & ", firstName = " & firstName & ", lastName = " & lastName & ", email = " & email & " WHERE ID = " & id & ""	
id = Request.QueryString("id")
set conn = server.CreateObject ("ADODB.Connection")
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & server.MapPath ("user_db.mdb")
set rs = server.CreateObject ("ADODB.Recordset")
conn.execute str	
rs.Update

set rs=nothing
set conn=nothing

Response.Redirect("testviewusers.asp")

%>

whats wrong with it? please help thanx alot! : o)

Hi there,

I think you need to
a) quote your strings
b) the value of the variable id is assigned after its use

that should fix it.

Cheers,

Paul.

str = “UPDATE user_details SET username = '” & username & “', password = '” & password & “', firstName = '” & firstName & “', lastName = '” & lastName & “', email = '” & email & “’ WHERE ID = '” & id & “'”

try that.. i put in the single quotes around your data

[QUOTE=doctorallia]
str = “UPDATE user_details SET username = '” & username & “', password = '” & password & “', firstName = '” & firstName & “', lastName = '” & lastName & “', email = '” & email & “’ WHERE ID = '” & id & “'”

try that.. i put in the single quotes around your data
[/QUOTE]

Hi, I tried this but same error…

[QUOTE=largerabbit]
Hi there,

I think you need to
a) quote your strings
b) the value of the variable id is assigned after its use

that should fix it.

Cheers,

Paul.
[/QUOTE]

Hi, I’m kinda newbie don’t seems to understand can you please give me some examples? thanx alot

The quoted string from doctorallia look perfect, but in your code you need to move the line

id = Request.QueryString(“id”)

above the sql string. Otherwise your value of id in the SQL will always be nothing.

Also, there are soem variables coming from form input and the id is coming from a query string? Is that what you are doing?

If you need more help, post the page that calls this script.

Cheers.

yea, if you are having trouble still.. post both your form input page and the asp page.

[QUOTE=doctorallia]
str = “UPDATE user_details SET username = '” & username & “', password = '” & password & “', firstName = '” & firstName & “', lastName = '” & lastName & “', email = '” & email & “’ WHERE ID = '” & id & “'”
[/QUOTE]

While that code is sufficient to test if the quoting was the only cause of the problem (because it’s definitely syntactically incorrect). However, it’s dangerous to use in a ‘production’ environment because it’s vulnerable to SQL insertion.

You should write a function to properly escape all the string variables in your queries.

hi guys this are the codes for the form page this page will call for the asp page i posted above. thanx for all your help!

<%
id = Request.QueryString(“id”)
set conn = server.CreateObject (“ADODB.Connection”)
conn.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & server.MapPath (“user_db.mdb”)
set rs = server.CreateObject (“ADODB.Recordset”)
rs.Open “SELECT * FROM user_details WHERE userID=”& id &“”, conn

%>
Users Modify ">

Modify Account

Username Password First Name Last Name Email
"> "> "> "> ">
<% set rs=nothing set conn=nothing %>

try using this for your modify data page…

<%

username = Request.Form(“username”)
password = Request.Form(“password”)
firstName = Request.Form(“first”)
lastName = Request.Form(“last”)
emailName = Request.Form(“email”)

id = Request.QueryString(“id”)

str = “UPDATE user_details SET username = '” & username & “', password = '” & password & “', firstName = '” & firstName & “', lastName = '” & lastName & “', email = '” & email & “’ WHERE ID = '” & id & “'”

set conn = server.CreateObject (“ADODB.Connection”)
conn.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & server.MapPath (“user_db.mdb”)
set rs = server.CreateObject (“ADODB.Recordset”)
conn.execute str
rs.Update

set rs=nothing
set conn=nothing

Response.Redirect(“testviewusers.asp”)

%>

[QUOTE=doctorallia]
try using this for your modify data page…

<%

username = Request.Form(“username”)
password = Request.Form(“password”)
firstName = Request.Form(“first”)
lastName = Request.Form(“last”)
emailName = Request.Form(“email”)

id = Request.QueryString(“id”)

str = “UPDATE user_details SET username = '” & username & “', password = '” & password & “', firstName = '” & firstName & “', lastName = '” & lastName & “', email = '” & email & “’ WHERE ID = '” & id & “'”

set conn = server.CreateObject (“ADODB.Connection”)
conn.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & server.MapPath (“user_db.mdb”)
set rs = server.CreateObject (“ADODB.Recordset”)
conn.execute str
rs.Update

set rs=nothing
set conn=nothing

Response.Redirect(“testviewusers.asp”)

%>
[/QUOTE]

Hi again, i’ve tried the code you provide but i have this same error.

Error Type:
Microsoft JET Database Engine (0x80040E14)
Syntax error in UPDATE statement.
/alle_new/modifydata.asp, line 17

is the ID field a number field ?

if so you dont need the ’ ’ .. you just need to add " & & strID & "

[QUOTE=Emagine]
is the ID field a number field ?

if so you dont need the ’ ’ .. you just need to add " & & strID & "
[/QUOTE]

i did that… and then…
AND the REAL reason it isnt working… you use a different variable name for email when you are making the sql string..
look at your original code.. i corrected it below

<%

username = Request.Form(“username”)
password = Request.Form(“password”)
firstName = Request.Form(“first”)
lastName = Request.Form(“last”)
emailName = Request.Form(“email”)

id = Request.QueryString(“id”)

str = “UPDATE user_details SET username = '” & username & “', password = '” & password & “', firstName = '” & firstName & “', lastName = '” & lastName & “', email = '” & emailName & "’ WHERE ID = " & id & “”

set conn = server.CreateObject (“ADODB.Connection”)
conn.Open “Provider=Microsoft.Jet.OLEDB.4.0;Data Source=” & server.MapPath (“user_db.mdb”)
set rs = server.CreateObject (“ADODB.Recordset”)
conn.execute str
rs.Update

set rs=nothing
set conn=nothing

Response.Redirect(“testviewusers.asp”)

%>

good point i didn’t see the veriable change.

also you will need to check the ID veriable i suggested as it depends if its a number or ot if you require the ‘’

erm… guys do you need my original file? i’ve been trying to solve this problem for weeks but still cant work. thanx alot!

Highflyer, the solution to the problem is above in doctorallia’s post.

[QUOTE=largerabbit]
Highflyer, the solution to the problem is above in doctorallia’s post.
[/QUOTE]

Still the same error…

my file. 1st page testviewusers.asp → modify.asp → modifydata.asp

sample2.zip (9.36 KB)

okay, working on it .. making progress! i found some errors

got it.. if you want me to explain what i changed let me know.

it was all in the modify data page.. so you can see it if you compare the old and new ones

fixed.zip (9.51 KB)