Click to See Complete Forum and Search --> : Searching databases


kimstar00
10-18-2006, 06:14 AM
i search for a customer id and if the customer id matches the one in the database a table is supposed to be formed containing some information. Why wont my asp file work properly?

Code for my html file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Task 1</title>
</head>
<body>
<h3>Task 1</h3>
<form id="customerform" action="task1.asp" method="get">
<h4>please fill in the following form</h4>
<p>Customer ID <input type="text" name="custID"/><br/>
<p><input type="submit" value="Submit">
<input type="reset" value="Reset"></p>
</form>
</body>
</html>


Code for my asp file
<%@ Language="VBScript" %>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<% set conn = server.createobject("ADODB.connection")
myConn.open "warehouse", "IWSDStudent", "assign2"
cID = request.form("custID")
mySQL = "select orderDate, orderNumber, shippingDate, shipped from orders,"
mySQL = mySQL & "where customerID = " & cID
set myRS = myConn.execute(mySQL)%>

<head>
<title>Task1</title>
</head>

<body>
<% if not(myRS.bof and myRS.eof) then %>
<p>Here are the details of <%=cID%>:</p>
<h3 style="text-align:center">Customer Table</h3>
<table border="1" summary="Customer Details">
<tr>
<th>Order Date</th>
<th>Order Number</th>
<th>Shipping Date</th>
<th>Shipped</th>
</tr>
<% do while not myRS.eof %>
<tr>
<td><%= myRS("orderDate")%></td>
<td><%= myRS("orderNumber")%></td>
<td><%= myRS("shippingDate")%></td>
<td><%= myRS("orderNumber")%></td>
</tr>
<% myRS.movenext
loop%>
</table>
<%else%>
<p>Sorry!! No Such Customer!</p>
<%end if%>
</body>
</html>

russell
10-18-2006, 10:49 AM
the form method is "Get" and the ASP is looking in the Post (form) collection.

Either change the form method to "post" or change your Request.Form to Request.QueryString

kimstar00
10-18-2006, 07:18 PM
it still doesnt work. theres something wrong with my asp file but i cant find wat it is.

kimstar00
10-18-2006, 09:52 PM
i get the error

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '='.

russell
10-18-2006, 10:13 PM
get rid of the last comma

mySQL = "select orderDate, orderNumber, shippingDate, shipped from orders,"

then do a response.write mySQL to see the query u r passing to the db.

kimstar00
10-19-2006, 05:25 AM
then do a response.write mySQL to see the query u r passing to the db.

ok i got rid of the comma, but i dont understand wat to do after that.

kimstar00
10-19-2006, 07:01 AM
this is wat i hav done so far.. but i get this error
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near '='.

/iwsd/IWSD2134/examples asp/asd/task1.asp, line 11

my html
<html>
<head>
<title>Example 2 Form</title>
</head>
<body>
<form id="SecondForm" method="post" action="getcustomername.asp">
<p>Enter the Customer ID:
<input type="text" name="custid" size="10" maxlength="10"/></p>
<input type="submit"/><input type="reset"/>
</form>
</body>
</html>

my asp

<%@ Language="VBScript" %>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<% set conn = server.createobject("ADODB.connection")
conn.open "warehouse", "IWSDStudent", "assign2"
cID = request.form("custID")
sql = "select orderDate, orderNumber, shippingDate, shipped from orders"
sql = sql & "where customerID =" & cID
set rs = conn.execute(sql)%>

<head>
<title>Task1</title>
</head>

<body>
<% if not(rs.bof and rs.eof) then %>
<p>Here are the details of <%=cID%>:</p>
<table border="1">
<tr>
<th>Order Date</th>
<th>Order Number</th>
<th>Shipping Date</th>
<th>Shipped</th>
</tr>
<% do while not rs.eof %>
<tr>
<td><%= rs ("orderDate")%></td>
<td><%= rs ("orderNumber")%></td>
<td><%= rs ("shippingDate")%></td>
<td><%= rs ("shipped")%></td>
</tr>
<% rs.movenext
loop
%>
</table>
<%else%>
<p>Sorry!! No Such Customer!</p>
<%end if%>
</body>
</html>

russell
10-19-2006, 09:34 AM
u need to see the value of cID, and the query. u also now have no space between "orders" and "where"


cID = request.form("custID")
' notice i added a spece at the end of the next line...
sql = "select orderDate, orderNumber, shippingDate, shipped from orders "
sql = sql & "where customerID =" & cID

Response.Write "<p>cID=" & cID & "</p>"
Response.Write "<p>sql=" & sql & "</p>"

set rs = conn.execute(sql)
what is the value of cID? What is the value of sql?