PDA

View Full Version : Asp coding: why it insert several time the same info into the table of database



SBUH
September 9th, 2003, 11:08 AM
Hello, I have asp code for login page. And if the username and password is correct, I want to insert into the caporder table the correspondent values in the specific column. But now when I run once the code, it insert into several columns of the caporder table with the same value if the username and password are correct. Could any one suggest how to modify the code? Thanks!



<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Open "Project"
dim username
username=Request.Form("user")
password=Request.Form("pass")
result=true

set rs = Server.CreateObject("ADODB.recordset")
sql="select username, password from customer"
rs.Open sql, conn
do until rs.EOF
for each x in rs.Fields
if username=x.value then
z=true
end if
if z=true then
if password=x.value then
session("ID")=username

conn.Execute "UPDATE Capproduct set cus_id='"&session("ID")&"' where ID='"&session("idnumber")&"' and sid='"&session.sessionid&"'"
conn.Execute "INSERT INTO Caporder VALUES ('"&session("ID")&"','"&session("idnumber")&"',getdate(),0,0,0,0,0,0,NULL,0,0)"----insert several times in caporder

Response.Write "<script>window.location='shipping.asp'</script>"
else result=false
end if
end if
next
rs.MoveNext
loop

rs.Close
conn.close

if result=false then
%>
<script type="text/javascript">
alert("The username and password are not matched, please type again! ");
</script>
<%
end if %>
<form name="form" method="post" action="login_after_cap.asp">
<p><font color="#0066FF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>Username:
</strong></font>
<input type="text" name="user">
</p>
<p> <font color="#0066FF" size="2" face="Verdana, Arial, Helvetica, sans-serif"><strong>
Password: </strong></font>
<input type="password" name="pass">
</p>
<input name="Submit" type="submit" value="login">
<input type="reset" name="Cancel" value="Clear">
</form>

abzoid
September 10th, 2003, 08:38 AM
I see the same issue as your prior problem. There is no WHERE condition in your SQL query to specify which record in the table you are attempting to insert the information into.

prstudio
September 10th, 2003, 12:44 PM
do you want the information to be stored under a certain name, or just added as people login example log:

A
B
B
A
C
D
A
A
each letter representing a person's login

also, you have your insert statement in a loop statement, that would do it my friend

if one person is logging in, from one page, then you don't need that loop statement in there

Digitalosophy
September 10th, 2003, 01:42 PM
PRINT YOUR SQL STATEMENT BEFORE EXECUTING AT ALL TIMES!
I advised this to you a while back. You'll see wheree the problem is there.

Your code is structured wierd to me, what your trying to do is simple, just not sure why you have loops as only one user will be logging in as prstudio said.

So, stop executing and start printing to see exactly where your problem is.