473,405 Members | 2,185 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

my sql query

omerbutt
638 512MB
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
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     username=Request("us_name")
  3.     password=Request("pass")
  4.     Dim strSQLus, conus, ADUSD
  5.  
  6.     set ADUSD=Server.CreateObject("ADODB.Recordset")
  7.     set conus=Server.CreateObject("ADODB.Connection")
  8.         conus="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/db1.mdb")
  9.  
  10.         //strSQLus = "SELECT login.user_n, login.pass_w FROM login;"
  11.         strSQLus = "insert into login(user_n, pass_w) "
  12.         strSQLus = strSQLus & " values('"& username &"','"& password &"') "
  13.         strSQLus = strSQLus & " where user_n <> '"& (Request.Form("us_name")) &"'"
  14.         ADUSD.CursorType = 2
  15.         ADUSD.LockType = 3
  16.         ADUSD.Open strSQLus, conus, 3
  17.         ADUSD.AddNew
  18.  
  19.         ADUSD.fields("user_n")=username
  20.         ADUSD.fields("pass_w")=password
  21.  
  22.         ADUSD.Update
  23.         ADUSD.Close
  24.  
  25.     set ADUSD = Nothing
  26.     set con = Nothing
  27.     Response.Redirect("Ad_us.asp")
  28. %>
Nov 26 '07 #1
5 1312
nedu
65
Hi,

U r using the where condition in INSERT SQL statement which is not possible. That is the error . . . .

Regards,
Nedu. M
Nov 27 '07 #2
JamieHowarth0
533 Expert 512MB
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.
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     myUsername=Request.QueryString("us_name")
  3.     myPassword=Request.QueryString("pass")
  4.  
  5.     Set myConn =Server.CreateObject("ADODB.Connection")
  6.     strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/db1.mdb")
  7.     myConn.Open strConn
  8. %>
Previously you had used conus as both your connection object and your connection string, which doesn't help.
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Set rsUser = Server.CreateObject("ADODB.Recordset")
  3.     strSQLus = "SELECT login.user_n, login.pass_w FROM login WHERE login.user_n = '" & myUsername & "';"
  4.     rsUser.Open strSQLus, myConn, 1, 1
  5.     'Now you've performed the search to see if the username already exists
  6.     '(note the specific use of single quotes so that SQL can interpret the
  7.     'string value of the username inputted)
  8.  
  9.     If rsUser.RecordCount = 1
  10.         'Username found, throw error back to user
  11.         Response.Write("Username already exists.<br />Please try again using a different username.")
  12.     Else
  13.         rsUser.Close
  14.        'Closes the recordset object so we can re-use it to insert the
  15.         'new username/password combination
  16.         strSQLus =  "INSERT INTO login VALUES ('"& myUsername &"','"& myPassword &"');"
  17.         rsUser.Open strSQLus, myConn, 2, 3
  18.     Response.Redirect("Ad_us.asp")
  19. End If
  20. %>
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
Nov 27 '07 #3
omerbutt
638 512MB
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.
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     myUsername=Request.QueryString("us_name")
  3.     myPassword=Request.QueryString("pass")
  4.  
  5.     Set myConn =Server.CreateObject("ADODB.Connection")
  6.     strConn="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/db1.mdb")
  7.     myConn.Open strConn
  8. %>
Previously you had used conus as both your connection object and your connection string, which doesn't help.
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Set rsUser = Server.CreateObject("ADODB.Recordset")
  3.     strSQLus = "SELECT login.user_n, login.pass_w FROM login WHERE login.user_n = '" & myUsername & "';"
  4.     rsUser.Open strSQLus, myConn, 1, 1
  5.     'Now you've performed the search to see if the username already exists
  6.     '(note the specific use of single quotes so that SQL can interpret the
  7.     'string value of the username inputted)
  8.  
  9.     If rsUser.RecordCount = 1
  10.         'Username found, throw error back to user
  11.         Response.Write("Username already exists.<br />Please try again using a different username.")
  12.     Else
  13.         rsUser.Close
  14.        'Closes the recordset object so we can re-use it to insert the
  15.         'new username/password combination
  16.         strSQLus =  "INSERT INTO login VALUES ('"& myUsername &"','"& myPassword &"');"
  17.         rsUser.Open strSQLus, myConn, 2, 3
  18.     Response.Redirect("Ad_us.asp")
  19. End If
  20. %>
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
Nov 27 '07 #4
JamieHowarth0
533 Expert 512MB
Hi omerbutt,

My apologies - if you are using a form (which I failed to spot) then use Request.Form
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     myUsername=Request.Form("us_name")
  3.     myPassword=Request.Form("pass")
  4.  
  5.     Set myConn =Server.CreateObject("ADODB.Connection")
  6.     strConn="Provider={Microsoft.Jet.OLEDB.4.0};Data Source=" & Server.MapPath("db/db1.mdb")
  7.     myConn.Open strConn
  8. 'Note the addition of curly brackets and removal of all spaces from your connection string
  9.  
  10.     Set rsUser = Server.CreateObject("ADODB.Recordset")
  11.     strSQLus = "SELECT login.user_n, login.pass_w FROM login WHERE login.user_n = '" & myUsername & "';"
  12.     rsUser.Open strSQLus, myConn, 1, 1
  13.     'Now you've performed the search to see if the username already exists
  14.     '(note the specific use of single quotes so that SQL can interpret the
  15.     'string value of the username inputted)
  16.  
  17.     If rsUser.RecordCount = 1
  18.         'Username found, throw error back to user
  19.         Response.Write("Username already exists.<br />Please try again using a different username.")
  20.     Else
  21.         rsUser.Close
  22.        'Closes the recordset object so we can re-use it to insert the
  23.         'new username/password combination
  24.         strSQLus =  "INSERT INTO login VALUES ('"& myUsername &"','"& myPassword &"');"
  25.         rsUser.Open strSQLus, myConn, 2, 3
  26.     Response.Redirect("Ad_us.asp")
  27. End If
  28. %>
This should now work.

medicineworker
Nov 27 '07 #5
omerbutt
638 512MB
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
Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim username, passw, RSANCR, connectionstr
  3.  
  4. username=request("us_name")
  5. passw=request("pass")
  6.  
  7. Set RSANCR=Server.CreateObject("ADODB.Recordset")
  8. Set connectionstr=Server.CreateObject("ADODB.Connection")
  9. connectionstr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/db1.mdb")
  10.  
  11. strSQL = "SELECT * FROM login;"
  12. RSANCR.OPEN strSQL, connectionstr, 3
  13.  
  14. foundIt=False
  15.  
  16. Do Until RSANCR.EOF OR foundIt    
  17. if (StrComp(RSANCR.Fields("user_n"), username, vbTextCompare) = 0) then
  18. foundIt=True 
  19. else
  20. RSANCR.MoveNext 
  21. End if 
  22. Loop
  23.  
  24.   if  foundIt = "False" Then
  25.     Dim r, constr, strSQL1
  26.     set r=Server.CreateObject("ADODB.Recordset")
  27.     set constr=Server.CreateObject("ADODB.Connection")
  28.     constr="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("db/db1.mdb")
  29.     strSQL1="Insert Into login(user_n,pass_w) Values('"& username &"','"& passw &"');"
  30.      r.Open strSQL1, constr, 3        
  31.      set r = Nothing
  32.      set constr = Nothing
  33.      Response.Redirect("Ad_us.asp")
  34. else
  35. RSANCR.Close
  36. Set RSANCR = Nothing     
  37. Set connectionstr= Nothing 
  38. Response.Redirect("Ad_us.asp?error=1") 
  39. End If 
  40. %>
  41.  
Hi omerbutt,

My apologies - if you are using a form (which I failed to spot) then use Request.Form
Expand|Select|Wrap|Line Numbers
  1. <%
  2.     myUsername=Request.Form("us_name")
  3.     myPassword=Request.Form("pass")
  4.  
  5.     Set myConn =Server.CreateObject("ADODB.Connection")
  6.     strConn="Provider={Microsoft.Jet.OLEDB.4.0};Data Source=" & Server.MapPath("db/db1.mdb")
  7.     myConn.Open strConn
  8. 'Note the addition of curly brackets and removal of all spaces from your connection string
  9.  
  10.     Set rsUser = Server.CreateObject("ADODB.Recordset")
  11.     strSQLus = "SELECT login.user_n, login.pass_w FROM login WHERE login.user_n = '" & myUsername & "';"
  12.     rsUser.Open strSQLus, myConn, 1, 1
  13.     'Now you've performed the search to see if the username already exists
  14.     '(note the specific use of single quotes so that SQL can interpret the
  15.     'string value of the username inputted)
  16.  
  17.     If rsUser.RecordCount = 1
  18.         'Username found, throw error back to user
  19.         Response.Write("Username already exists.<br />Please try again using a different username.")
  20.     Else
  21.         rsUser.Close
  22.        'Closes the recordset object so we can re-use it to insert the
  23.         'new username/password combination
  24.         strSQLus =  "INSERT INTO login VALUES ('"& myUsername &"','"& myPassword &"');"
  25.         rsUser.Open strSQLus, myConn, 2, 3
  26.     Response.Redirect("Ad_us.asp")
  27. End If
  28. %>
This should now work.

medicineworker
Nov 28 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
29
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"...
9
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...
3
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...
4
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...
14
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. ...
0
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...
6
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 ...
4
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...
6
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
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
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.