hi i am making an application with the help of html asp and javascript ihave made a New login form and when it submits its values on to another page to create the login and save it into the database i want to make a check that the user name that the person has choosed to create, exists in the database or not i have used the following query but it is giving me error
Error Type:
Microsoft JET Database Engine (0x80040E14)
Missing semicolon (;) at end of SQL statement.
/ASHAR/Ad_us_done.asp, line 16
any body can help me ? ....fanks in advance :)
Ad_us_done.asp -
<%
-
username=Request("us_name")
-
password=Request("pass")
-
Dim strSQLus, conus, ADUSD
-
-
set ADUSD=Server.CreateObject("ADODB.Recordset")
-
set conus=Server.CreateObject("ADODB.Connection")
-
conus="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/db1.mdb")
-
-
//strSQLus = "SELECT login.user_n, login.pass_w FROM login;"
-
strSQLus = "insert into login(user_n, pass_w) "
-
strSQLus = strSQLus & " values('"& username &"','"& password &"') "
-
strSQLus = strSQLus & " where user_n <> '"& (Request.Form("us_name")) &"'"
-
ADUSD.CursorType = 2
-
ADUSD.LockType = 3
-
ADUSD.Open strSQLus, conus, 3
-
ADUSD.AddNew
-
-
ADUSD.fields("user_n")=username
-
ADUSD.fields("pass_w")=password
-
-
ADUSD.Update
-
ADUSD.Close
-
-
set ADUSD = Nothing
-
set con = Nothing
-
Response.Redirect("Ad_us.asp")
-
%>
5 1312
Hi,
U r using the where condition in INSERT SQL statement which is not possible. That is the error . . . .
Regards,
Nedu. M
Hi omerbutt,
The reason you have an error in your code is due to the syntax in a couple of places. INSERT INTO statements do not accept WHERE clauses. You must perform a SELECT FROM which searches for the username, then check the number of records returned - if 1, then the username exists, and if 0, then the username doesn't exist. If you get any other number then there's an error in your connection or your code somewhere. -
<%
-
myUsername=Request.QueryString("us_name")
-
myPassword=Request.QueryString("pass")
-
-
Set myConn =Server.CreateObject("ADODB.Connection")
-
strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/db1.mdb")
-
myConn.Open strConn
-
%>
Previously you had used conus as both your connection object and your connection string, which doesn't help. -
<%
-
Set rsUser = Server.CreateObject("ADODB.Recordset")
-
strSQLus = "SELECT login.user_n, login.pass_w FROM login WHERE login.user_n = '" & myUsername & "';"
-
rsUser.Open strSQLus, myConn, 1, 1
-
'Now you've performed the search to see if the username already exists
-
'(note the specific use of single quotes so that SQL can interpret the
-
'string value of the username inputted)
-
-
If rsUser.RecordCount = 1
-
'Username found, throw error back to user
-
Response.Write("Username already exists.<br />Please try again using a different username.")
-
Else
-
rsUser.Close
-
'Closes the recordset object so we can re-use it to insert the
-
'new username/password combination
-
strSQLus = "INSERT INTO login VALUES ('"& myUsername &"','"& myPassword &"');"
-
rsUser.Open strSQLus, myConn, 2, 3
-
Response.Redirect("Ad_us.asp")
-
End If
-
%>
Your other problem lies in the fact that you are performing an insert query, which once executed successfully, does not return a recordset - yet you were trying to use the AddNew method to try and add to a recordset that has (in this particular instance) not been returned.
You are supposed to use the AddNew method where you have already SELECTed a number of records from a table/query and want to insert new data into the recordset.
Hope this helps.
medicineworker
sir as u told me so i used ur way to use myconn and constr seperately but it produces error on the line where i am trying to open the connection string myconn.Open connstr.......and the errror is
Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: ''
/ashar/Ad_us_done.asp, line 10
whereas if i use the same method as i used before using Connus for both object and string it runs fine but still add the names which exist in the data base
for that case i tried to print the query "select * from login where login.user_n = '"& username &"'" and yes inbtween 1 thing more that the method that you used Request.Querystring("user_n") to get the values when i try to print the value in the username it is blank whereas using Request("user_n") display the correct value but it isnt comparing it from the database
when i print the strSQL it displays these values in it
1...when i use request.querystring("user_n")
Select * From login Where login.user_n = '';
2.....when i used request("user_n")
Select * From login Where login.user_n = 'Omer Aslam';
can ya help me out i once used the same way for the editing of records where i was passing the primary key and used to get it on the other pagehaving the name id_no and then compared it with the primarykeys in the db to edit the specific record but there i used the clng(request.querystring("id_no")) to make it correctly work do i have to use some funtion of the same kind which should change the requested name into string or wot .......u can tell me better
Hi omerbutt,
The reason you have an error in your code is due to the syntax in a couple of places. INSERT INTO statements do not accept WHERE clauses. You must perform a SELECT FROM which searches for the username, then check the number of records returned - if 1, then the username exists, and if 0, then the username doesn't exist. If you get any other number then there's an error in your connection or your code somewhere. -
<%
-
myUsername=Request.QueryString("us_name")
-
myPassword=Request.QueryString("pass")
-
-
Set myConn =Server.CreateObject("ADODB.Connection")
-
strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/db1.mdb")
-
myConn.Open strConn
-
%>
Previously you had used conus as both your connection object and your connection string, which doesn't help. -
<%
-
Set rsUser = Server.CreateObject("ADODB.Recordset")
-
strSQLus = "SELECT login.user_n, login.pass_w FROM login WHERE login.user_n = '" & myUsername & "';"
-
rsUser.Open strSQLus, myConn, 1, 1
-
'Now you've performed the search to see if the username already exists
-
'(note the specific use of single quotes so that SQL can interpret the
-
'string value of the username inputted)
-
-
If rsUser.RecordCount = 1
-
'Username found, throw error back to user
-
Response.Write("Username already exists.<br />Please try again using a different username.")
-
Else
-
rsUser.Close
-
'Closes the recordset object so we can re-use it to insert the
-
'new username/password combination
-
strSQLus = "INSERT INTO login VALUES ('"& myUsername &"','"& myPassword &"');"
-
rsUser.Open strSQLus, myConn, 2, 3
-
Response.Redirect("Ad_us.asp")
-
End If
-
%>
Your other problem lies in the fact that you are performing an insert query, which once executed successfully, does not return a recordset - yet you were trying to use the AddNew method to try and add to a recordset that has (in this particular instance) not been returned.
You are supposed to use the AddNew method where you have already SELECTed a number of records from a table/query and want to insert new data into the recordset.
Hope this helps.
medicineworker
Hi omerbutt,
My apologies - if you are using a form (which I failed to spot) then use Request.Form -
<%
-
myUsername=Request.Form("us_name")
-
myPassword=Request.Form("pass")
-
-
Set myConn =Server.CreateObject("ADODB.Connection")
-
strConn="Provider={Microsoft.Jet.OLEDB.4.0};Data Source=" & Server.MapPath("db/db1.mdb")
-
myConn.Open strConn
-
'Note the addition of curly brackets and removal of all spaces from your connection string
-
-
Set rsUser = Server.CreateObject("ADODB.Recordset")
-
strSQLus = "SELECT login.user_n, login.pass_w FROM login WHERE login.user_n = '" & myUsername & "';"
-
rsUser.Open strSQLus, myConn, 1, 1
-
'Now you've performed the search to see if the username already exists
-
'(note the specific use of single quotes so that SQL can interpret the
-
'string value of the username inputted)
-
-
If rsUser.RecordCount = 1
-
'Username found, throw error back to user
-
Response.Write("Username already exists.<br />Please try again using a different username.")
-
Else
-
rsUser.Close
-
'Closes the recordset object so we can re-use it to insert the
-
'new username/password combination
-
strSQLus = "INSERT INTO login VALUES ('"& myUsername &"','"& myPassword &"');"
-
rsUser.Open strSQLus, myConn, 2, 3
-
Response.Redirect("Ad_us.asp")
-
End If
-
%>
This should now work.
medicineworker
hi medicineworker,
looks like i found a solution for my code check this out how i did it and its working perfectly fine ;)....but any way really appereciate ur help an advises they they were really percious and useful for me thanks aloot looking forward in future
regards,
Omer -
<%
-
Dim username, passw, RSANCR, connectionstr
-
-
username=request("us_name")
-
passw=request("pass")
-
-
Set RSANCR=Server.CreateObject("ADODB.Recordset")
-
Set connectionstr=Server.CreateObject("ADODB.Connection")
-
connectionstr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/db1.mdb")
-
-
strSQL = "SELECT * FROM login;"
-
RSANCR.OPEN strSQL, connectionstr, 3
-
-
foundIt=False
-
-
Do Until RSANCR.EOF OR foundIt
-
if (StrComp(RSANCR.Fields("user_n"), username, vbTextCompare) = 0) then
-
foundIt=True
-
else
-
RSANCR.MoveNext
-
End if
-
Loop
-
-
if foundIt = "False" Then
-
Dim r, constr, strSQL1
-
set r=Server.CreateObject("ADODB.Recordset")
-
set constr=Server.CreateObject("ADODB.Connection")
-
constr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/db1.mdb")
-
strSQL1="Insert Into login(user_n,pass_w) Values('"& username &"','"& passw &"');"
-
r.Open strSQL1, constr, 3
-
set r = Nothing
-
set constr = Nothing
-
Response.Redirect("Ad_us.asp")
-
else
-
RSANCR.Close
-
Set RSANCR = Nothing
-
Set connectionstr= Nothing
-
Response.Redirect("Ad_us.asp?error=1")
-
End If
-
%>
-
Hi omerbutt,
My apologies - if you are using a form (which I failed to spot) then use Request.Form -
<%
-
myUsername=Request.Form("us_name")
-
myPassword=Request.Form("pass")
-
-
Set myConn =Server.CreateObject("ADODB.Connection")
-
strConn="Provider={Microsoft.Jet.OLEDB.4.0};Data Source=" & Server.MapPath("db/db1.mdb")
-
myConn.Open strConn
-
'Note the addition of curly brackets and removal of all spaces from your connection string
-
-
Set rsUser = Server.CreateObject("ADODB.Recordset")
-
strSQLus = "SELECT login.user_n, login.pass_w FROM login WHERE login.user_n = '" & myUsername & "';"
-
rsUser.Open strSQLus, myConn, 1, 1
-
'Now you've performed the search to see if the username already exists
-
'(note the specific use of single quotes so that SQL can interpret the
-
'string value of the username inputted)
-
-
If rsUser.RecordCount = 1
-
'Username found, throw error back to user
-
Response.Write("Username already exists.<br />Please try again using a different username.")
-
Else
-
rsUser.Close
-
'Closes the recordset object so we can re-use it to insert the
-
'new username/password combination
-
strSQLus = "INSERT INTO login VALUES ('"& myUsername &"','"& myPassword &"');"
-
rsUser.Open strSQLus, myConn, 2, 3
-
Response.Redirect("Ad_us.asp")
-
End If
-
%>
This should now work.
medicineworker
Sign in to post your reply or Sign up for a free account.
Similar topics
by: jaysonsch |
last post by:
Hello!
I am having some problems with a database query that I am trying to do.
I am trying to develop a way to search a database for an entry and
then edit the existing values. Upon submit, the...
|
by: shank |
last post by:
1) I'm getting this error: Syntax error (missing operator) in query
expression on the below statement. Can I get some advice.
2) I searched ASPFAQ and came up blank. Where can find the "rules"...
|
by: netpurpose |
last post by:
I need to extract data from this table to find the lowest prices of
each product as of today. The product will be listed/grouped by the
name only, discarding the product code - I use...
|
by: Harvey |
last post by:
Hi,
I try to write an asp query form that lets client search any text-string and
display all pages in my web server that contain the text. I have IIS 6.0 on a
server 2003. The MSDN site says...
|
by: Diamondback |
last post by:
I have two tables, WIDGETS and VERSIONS. The WIDGETS table has
descriptive information about the widgets while the VERSIONS table
contains IDs relating to different iterations of those widgets...
|
by: Dave Thomas |
last post by:
If I have a table set up like this:
Name | VARCHAR
Email | VARCHAR
Age | TINYINT | NULL (Default: NULL)
And I want the user to enter his or her name, email, and age - but AGE
is optional.
...
|
by: starace |
last post by:
I have designed a form that has 5 different list boxes where the
selections within each are used as criteria in building a dynamic
query. Some boxes are set for multiple selections but these list...
|
by: jjturon |
last post by:
Can anyone help me??
I am trying to pass a Select Query variable to a table using Dlookup
and return the value to same select query but to another field.
Ex.
SalesManID ...
|
by: Stan |
last post by:
I am using MS Office Access 2003 (11.5614). My basic question is can
I run a query of a query datasheet. I want to use more that one
criteria and can not get that query to work. I thought I...
|
by: jsacrey |
last post by:
Hey everybody, got a secnario for ya that I need a bit of help with.
Access 97 using linked tables from an SQL Server 2000 machine.
I've created a simple query using two tables joined by one...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |