| Author |
Topic Search Topic Options
|
adnan248999
Newbie
Joined: 30 November 2003
Location: United Kingdom
Status: Offline
Points: 26
|
Post Options
Thanks(0)
Quote Reply
Topic: What the hell? Posted: 01 December 2003 at 8:11am |
I am using an ms access database and trying to insert data into it using sql INSERT INTO and i get an error saying:
"Syntax error in INSERT INTO statement."
What the hell is going on? I have check my data to make sure they are string values since the field types in my databse are ALL set to text.
This is my code:
<%
Set adocon = Server.CreateObject("ADODB.Connection")
adocon.Provider = "Microsoft.Jet.OLEDB.4.0"
adocon.open (server.mappath("mydb.mdb"))
Dim insertuser
insertuser = "INSERT INTO tblAuthor (Username, Realname, Password) VALUES('"®username&"','"®userrealname& "','"®userpass&"')"
adocon.execute(insertuser)
set adocon=nothing
response.redirect("default.asp")
%>
|
 |
Eftie
Groupie
Joined: 17 March 2003
Location: Netherlands
Status: Offline
Points: 140
|
Post Options
Thanks(0)
Quote Reply
Posted: 01 December 2003 at 8:39am |
I think there are ' too much at the end:
insertuser = "INSERT INTO tblAuthor (Username, Realname, Password) VALUES('"®username&"','"®userrealname& "','"®userpass&"')"
should be
insertuser = "INSERT INTO tblAuthor (Username, Realname, Password) VALUES('"®username&"','"®userrealname& "'," & reguserpass & ")"
|
|
Eftie
|
 |
adnan248999
Newbie
Joined: 30 November 2003
Location: United Kingdom
Status: Offline
Points: 26
|
Post Options
Thanks(0)
Quote Reply
Posted: 01 December 2003 at 9:10am |
Eftie wrote:
I think there are ' too much at the end:
insertuser = "INSERT INTO tblAuthor (Username, Realname, Password) VALUES('"®username&"','"®userrealname& "','"®userpass&"')"
should be
insertuser = "INSERT INTO tblAuthor (Username, Realname, Password) VALUES('"®username&"','"®userrealname& "'," & reguserpass & ")"
|
Nope that didn't help one bit
|
 |
Gullanian
Senior Member
Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
|
Post Options
Thanks(0)
Quote Reply
Posted: 01 December 2003 at 10:07am |
Correct syntax is:
INSERT INTO tblAuthor (Username, Realname, Password) VALUES('" & regusername & "','" & reguserrealname & "','" & reguserpass & "')
Gaps between the &'s are pretty important I think. If it doesnt work make sure those 3 variables are holding values
|
 |
Eftie
Groupie
Joined: 17 March 2003
Location: Netherlands
Status: Offline
Points: 140
|
Post Options
Thanks(0)
Quote Reply
Posted: 01 December 2003 at 10:24am |
Found it:
username and password are protected variables, looks like it
Rename the names in tblAuthor to UUsername and UPassword and use:
Set adocon = Server.CreateObject("ADODB.Connection") adocon.Provider = "Microsoft.Jet.OLEDB.4.0" adocon.open (server.mappath("mydb.mdb"))
Dim insertuser
'Used for testing regusername = "nickname" reguserrealname = "realname" reguserpass = "secret"
insertuser = "INSERT INTO tblAuthor (UUsername, Realname, UPassword) VALUES ('"®username&"','"®userrealname& "','"®userpass&"')"
response.write insertuser
adocon.execute(insertuser)
set adocon=nothing
'response.redirect("default.asp")
Edit: just tested this script on my localhost and this works.
Regards
Edited by Eftie
|
|
Eftie
|
 |
adnan248999
Newbie
Joined: 30 November 2003
Location: United Kingdom
Status: Offline
Points: 26
|
Post Options
Thanks(0)
Quote Reply
Posted: 01 December 2003 at 11:36am |
Hey thanx alot that helped the problems is now solved thanx to all that tried to help. One question though...Does anyone know where to get a list of reserved names that access uses so i know what not to name my fields in the database.
Thanx
|
 |
Eftie
Groupie
Joined: 17 March 2003
Location: Netherlands
Status: Offline
Points: 140
|
Post Options
Thanks(0)
Quote Reply
Posted: 01 December 2003 at 1:49pm |
|
|
|
Eftie
|
 |
pmormr
Senior Member
Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
|
Post Options
Thanks(0)
Quote Reply
Posted: 01 December 2003 at 5:01pm |
too many darn words
|
|
|
 |