Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 05-18-2007, 02:34 PM   PM User | #1
jennypretty
Regular Coder

 
Join Date: Nov 2005
Posts: 225
Thanks: 2
Thanked 0 Times in 0 Posts
jennypretty is an unknown quantity at this point
asp help for newbie syntax error

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
%>
jennypretty is offline   Reply With Quote
Old 05-18-2007, 03:07 PM   PM User | #2
nikkiH
Senior Coder

 
nikkiH's Avatar
 
Join Date: Jun 2005
Location: Near Chicago, IL, USA
Posts: 1,973
Thanks: 1
Thanked 32 Times in 31 Posts
nikkiH is on a distinguished road
Where is ID defined?
__________________

If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
Bored? Visit
http://www.kaelisspace.com/
nikkiH is offline   Reply With Quote
Old 05-18-2007, 03:28 PM   PM User | #3
jennypretty
Regular Coder

 
Join Date: Nov 2005
Posts: 225
Thanks: 2
Thanked 0 Times in 0 Posts
jennypretty is an unknown quantity at this point
ID is defined from previous page.
thanks.
jennypretty is offline   Reply With Quote
Old 05-18-2007, 05:43 PM   PM User | #4
jennypretty
Regular Coder

 
Join Date: Nov 2005
Posts: 225
Thanks: 2
Thanked 0 Times in 0 Posts
jennypretty is an unknown quantity at this point
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.
jennypretty is offline   Reply With Quote
Old 05-18-2007, 07:57 PM   PM User | #5
TheShaner
Senior Coder

 
TheShaner's Avatar
 
Join Date: Sep 2005
Location: Orlando, FL
Posts: 1,125
Thanks: 2
Thanked 40 Times in 40 Posts
TheShaner will become famous soon enoughTheShaner will become famous soon enough
1st, you've left out important code. Which line is 105? We need to know that to see the error.

2nd:
Quote:
<%
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:
Quote:
<%
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
TheShaner is offline   Reply With Quote
Old 06-01-2007, 07:06 PM   PM User | #6
jennypretty
Regular Coder

 
Join Date: Nov 2005
Posts: 225
Thanks: 2
Thanked 0 Times in 0 Posts
jennypretty is an unknown quantity at this point
thanks.
It worked.
jennypretty is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:06 AM.


Advertisement
Log in to turn off these ads.