Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using ASP to execute SQL

Status
Not open for further replies.

UnfitElf

Programmer
Dec 3, 2002
24
NZ
Hey all...

I am creating a login page but i keep on getting this error:

Source:Microsoft OLE DB Provider for ODBC Drivers,[Microsoft][ODBC Microsoft Access Driver] Missing semicolon(;) at end of SQL statement

Now here is the code i have done...

sSQL = &quot;INSERT INTO Users (Username, Password) VALUES ('&quot; & Request(&quot;Username&quot;) & &quot;','&quot; & Request(&quot;Password&quot;) & &quot;') Where username <> '&quot; & Request(&quot;Username&quot;) & &quot;'&quot;
Set oConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
oConn.Open &quot;DSN=myDatabase&quot;

Set rsValidation = oConn.execute (sSQL)

I do know that SQL needs a &quot;;&quot; at the end of each thing but i have added one where i thought it should go but i end up with the same error.

any help??

Thanks in advance :)
 
Your error is here:
Code:
Where username <> '&quot; & Request(&quot;Username&quot;) & &quot;'&quot;

When inserting a record into the db you are inserting a brand spanking new record, so you can't have qualifiers on the argument. You really have only two options, add the record or don't add the record (ie, don't execute it from the ASP :) )

The std syntax of the insert statement is:
INSERT INTO tablename VALUES(value1,[value2[/i]...valueN)
or
INSERT INTO tablename(field1, field2,...fieldN) VALUES(value1,[value2[/i]...valueN)

The first assumes you are going to assign values to every field in your table in the same exact order they are in in the database. It can get messy.
The second allows you to assign wich field you are going to set and the order.

That is basically all you are allowed to do with that :)

Hope this helped,
-Tarwn Experts are only people who have realized how much they will never know about a language.
________________________________________________________________________________
Want to get great answers to your Tek-Tips questions? Have a look at faq333-2924
 
Thanks for that.

So is there any way that you can think of that will allow me to check the database to see if there is already a user with the same username that the new user is trying to regester, with pref only a few lines of code.

Thanks for your help.
 
First you check if there is a record with the same UserName. Is this not the case you insert a new record.

Set rsUser = oConn.Execute(&quot;SELECT Username FROM Users WHERE Username = '&quot; & Request(&quot;Username&quot;) & &quot;'&quot;)

If rsUser.EOF Then 'No record found with the same Username
oConn.Execute(&quot;INSERT INTO Users (Username, Password) VALUES ('&quot; & Request(&quot;Username&quot;) & &quot;','&quot; & Request(&quot;Password&quot;) & &quot;')
Else
'Tell the user he has to pick another name
End If

Hope this helps.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top