...

View Full Version : asp help for newbie syntax error



jennypretty
05-18-2007, 02:34 PM
Hello,

I am a newbie in ASP, I am trying to list a specific record and update it from the db table. But I keep getting this error:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '='.
student_edit.asp, line 105
Thanks for your help.

Here is my code:
<!-- #INCLUDE VIRTUAL="connect.asp" -->
<%
function fixStr( theString )
fixStr = replace( theString, "'", "''")
end function

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open strConnect
%>

<%
sqlString = "select * from jenny where ID =" & ID
Student name: <input type="text" name="name" value="<%=Student_name%>"><br />
Country: <input type="text" name="country" value="<%=country%>"><br />
Phone: <input type="text" name="phone" value="<%=phone%>"><br />
Email: <input type="text" name="email" value="<%=email%>"><br />

<%
sqlString = "update jenny set " &_
"Student name ='" & fixStr( Student_name ) & "', " &_
"Country ='" & fixStr( Country ) & "', " &_
"Phone ='" & fixStr( Phone ) & "', " &_
"Email ='" & fixStr( Email ) & "' where ID =" & ID

dbCon.Execute sqlString
%>

nikkiH
05-18-2007, 03:07 PM
Where is ID defined?

jennypretty
05-18-2007, 03:28 PM
ID is defined from previous page.
thanks.

jennypretty
05-18-2007, 05:43 PM
Hello,
I defined the Id by ID=request( "id" ), no more syntax errors. But it shows all blank text boxes.
What did I do wrong?
thanks.

TheShaner
05-18-2007, 07:57 PM
1st, you've left out important code. Which line is 105? We need to know that to see the error.

2nd:

<%
sqlString = "select * from jenny where ID =" & ID
Student name: <input type="text" name="name" value="<%=Student_name%>"><br />
Country: <input type="text" name="country" value="<%=country%>"><br />
Phone: <input type="text" name="phone" value="<%=phone%>"><br />
Email: <input type="text" name="email" value="<%=email%>"><br />
The above has an open ended <% with none closing. Like NikkiH stated, ID is not defined. It won't carry over from the previous page, unless it was submitted in a form, sent over the querystring, or stored in a session, in which case you'll need to use the Request method for retrieving the value. I also don't see where the Student_name, country, phone, and email variables are being set.

3rd:

<%
sqlString = "update jenny set " &_
"Student name ='" & fixStr( Student_name ) & "', " &_
"Country ='" & fixStr( Country ) & "', " &_
"Phone ='" & fixStr( Phone ) & "', " &_
"Email ='" & fixStr( Email ) & "' where ID =" & ID

dbCon.Execute sqlString
%>
The above should be at the top of your page after the form has been submitted to update the values. You would also need to retrieve those values using Request.Form. And last, it's good practice to never use spaces in your field names. If you do, you need to enclose the field with [] brackets, i.e. [Student Name]. However, it's just easier to never use spaces and use underscores instead to break up field names.

-Shane

jennypretty
06-01-2007, 07:06 PM
thanks.
It worked.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum