...

View Full Version : problem with query



robojob
08-12-2005, 08:59 PM
i have a login script and i am trying to query the database based on the username that is stored in a session, the code i have for this page is below. When i login and it directs me to that page i see the following error:

Script error detected at line 21.
Source line: rs.Open strSQL, adoCon, 3, 3
Description: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.


I am guessing that i have done summit wrong with the coding of the opening of the database and the query.... can anyone tell me whats wrong with it please....



<%
username = Session("loginfailure")
if ("" = username) Then
response.Write("Sorry, you are not logged in.")
response.End
End if
%>

<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rs 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database

Set adoCon = Server.CreateObject("ADODB.Connection")
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("project_database.mdb")
'adoCon.Open "DSN=login"
Set rs = Server.CreateObject("ADODB.Recordset")

strSQL = "SELECT * FROM register Where username = '"& Session("username") &"';"
rs.Open strSQL, adoCon, 3, 3

IF NOT rs.EOF THEN

FName=rs("user_name")


rs.Close
Set rs = Nothing
adoCon.Close
Set adoCon = Nothing
End If

%>

<HTML>
<head>
<title>Final Login Page after logged in</title>
<style>
</head>
<body TOPMARGIN=0 LEFTMARGIN=5 MARGINWIDTH=5 MARGINHEIGHT=0>
<br>
<br>
<br>
<table valign=top border=0 bordercolor="#ffffff" width="100%" cellspacing=0 cellpadding=0>
<tr>
<td align="left" valign=top>

<TABLE WIDTH="80%" BORDER="0" CELLSPACING="0" CELLPADDING="1" ALIGN="center" style="border-style: solid; border-color: #0000CC">
<TR>
<TD BGCOLOR="#0000FF" CLASS="hea" HEIGHT="20">
<DIV ALIGN="center"><font face="Verdana,Arial" color="#ffffff"><b>Final
Page</b></font></DIV>
</TD>
</TR>

<TR>
<TD BGCOLOR="#33ccff">
<TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="8" BGCOLOR="#EFEFEF">
<TR>
<TD CLASS="small">


<p align="left"><font size="3" face="Verdana,Arial" color="#0000ff"><B>Congratulation!
</B></font>




<p align="left"><font size="3" face="Verdana,Arial" color="#0000ff"><b>
<br>You
have successfully logged in to our site</b></font><p align="left"><font size="3" face="Verdana,Arial" color="#0000ff">


<p align="left">&nbsp;



</TD>
</TR>
</TABLE>
</TD>
</TR>
</TABLE>



</table>
Welcome <%Fname%>.
<a href="logout.asp">Log out</a>

</BODY>
</html>

neocool00
08-12-2005, 11:58 PM
strSQL = "SELECT * FROM register Where username = '"& Session("username") &"';"
Ditch the ";" at the end of your select statement.

robojob
08-13-2005, 12:47 AM
Nope still getting this error:

Script error detected at line 21.
Source line: rs.Open strSQL, adoCon, 3, 3
Description: [Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

Bullschmidt
08-13-2005, 02:05 AM
Here are a couple things to try (otherwise no idea):

Maybe Session("username") is actually blank at the time.

Or perhaps try this:

strSQL = "SELECT * FROM [register] Where [username] = '" & Session("username") &"';"

Freon22
08-13-2005, 02:40 AM
Try doing a Response.Write strSQL to make sure that session("username") has something in it.

robojob
08-13-2005, 10:38 AM
Here are a couple things to try (otherwise no idea):

Maybe Session("username") is actually blank at the time.

Or perhaps try this:

strSQL = "SELECT * FROM [register] Where [username] = '" & Session("username") &"';"


That didnt work and i have tried the response.write and the session definatley has something in it, i did that before i did this part to make sure that was working!

Any other ideas,???

robojob
08-13-2005, 10:48 AM
sorted it, there was a missing _ between user and name in the query so it was looking for a column in the database that isnt there!!! my fault! thanks for your help!!

Bullschmidt
08-13-2005, 03:14 PM
Alright way to go!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum