ASP - restricting display all records - Asked By Imran Khurshid on 18-Jul-14 01:16 PM

i've already fix the previous problem to search a specific
records through dsn by the help of you at 4guysfromrolla forum. now i'm searching the record through dsnless connection. when we type the specific number at search.asp it works fine. but if we
open the page track.asp alone it shows all the record. i want that if the user directly type the page track.asp, he would see nothing.belw is the code of track.asp

<%@ LANGUAGE="VBSCRIPT" %>
<html>
<head>
<title>Search Results!</title>
</head>

<body>
<%

Dim SqlJunk


Set dbGlobalWeb = Server.CreateObject("ADODB.Connection")
dbGlobalWeb.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\creativepk\db\trackingold.mdb"))

SqlJunk = "SELECT * FROM customer"

If Request.Form("TypeSearch") = "BLNUMBER" Then
	SqlJunk = SqlJunk & " WHERE BLNUMBER LIKE '" & Request.Form("DaInBox") & "'"
End If

Set rsGlobalWeb = Server.CreateObject("ADODB.Recordset")
rsGlobalWeb.Open SqlJunk, dbGlobalWeb, 3,3
%>
<%
If rsGlobalWeb.BOF and rsGlobalWeb.EOF Then%>

<h2 align="center">We did not find a match!</h2>
<%Else%>


<%If Not rsGlobalWeb.BOF Then%>


<BR> 
<BR> 
<BR> 
<BR> 
<center><h2>Here are the results of your search:</h2></center>
<table BORDER="1" width="100%" cellpadding="3">
  <tr>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">BL NUMBER </font></th>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">CONNECTING VESSEL </font></th>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">ETD </font></th>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">ETA </font></th>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">FINAL DESTINATION </font></th>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">DELIVERY AGENT </font></th>
  </tr>
<%
	Do While Not rsGlobalWeb.EOF
	%>
  <tr>
    <td><%=rsGlobalWeb("BLNUMBER")%> 

</td>
    <td><%=rsGlobalWeb("CONNECTINGVESSEL")%>
</td>
    <td><%=rsGlobalWeb("ETD")%>
</td>
    <td><%=rsGlobalWeb("ETA")%>
<td><%=rsGlobalWeb("FINALDESTINATION")%>
</td>
<td><%=rsGlobalWeb("DELIVERYAGENT")%>
</td>
</td>
<% rsGlobalWeb.MoveNext
	Loop
	%>
</table>
<%End If%>
<%End If%>
<%
rsGlobalWeb.Close
dbGlobalWeb.Close
%>
</body>
</html>

Querystring or hidden form field... - Asked By Robbe Morris on 21-May-01 09:21 PM

most folks use either of these two.  If they aren't there, then either redirect to a page or show "no records" found.

Your script is pretty much wide open.  A simple check for a querystring value or hidden form value should do the trick.
Asked By Imran Khurshid on 18-Jul-14 01:17 PM
i'm a newbie. would u Please let me know how to do that?

Something like this... - Asked By Robbe Morris on 21-May-01 09:45 PM

Search page form tag:  

<form name=form1 method=post action=http://www.yourdomain.com/search.asp?POST=1>

' your search results form page code goes here.

</form>


Search results page might look like this:



<%

   If Request.QueryString("POST") = "1" then

    ' All your database code goes here.


   else
     response.write "no results found."
   end if


%>
How did you find this site? - Asked By Robbe Morris on 21-May-01 09:46 PM
...
Asked By Imran Khurshid on 21-May-01 10:00 PM
i'm searching that page track.asp through search.asp. below is the code of search.asp and it works fine. but i wish
nothing to be appeared when type mydomain.com/track.asp in the addresbar.

<center><h1> Search The Bl Number</h1>
<form action="track.asp" method="post"
    name="DaForm" align="center">
      <select name="TypeSearch" size="1">
            <option selected value="BLNUMBER">BL NUMBER</option>

          </select></td>
          <td width="310" align="right"><input type="text" size="15" name="DaInBox"></td>
        </tr>
        <tr>
          <input type="submit"
          name="B1" value="Search!"><input type="reset" name="B2" value="Clear"></center>
Asked By Imran Khurshid on 21-May-01 10:04 PM
i've already said that i've posted a problem at aspmessageboard.com and prblem was fixed by eggheadcafe.com
the mention on the reply address
Right... - Asked By Robbe Morris on 21-May-01 10:05 PM
...I understand what you are trying to do.  You will need something carried over from search.asp to tell track.asp that you either do or do not want to execute a search.

search.asp should either post the form to track.asp with a hidden field or querystring that track.asp can check for prior to even writing any HTML much less display search results.

 track.asp would contain something like

<%

   if Request.QueryString("POST") = "1" then
    ' the code you have just mentioned.
   else
    ' show no results or a blank page.
   end if

%>

You could also reference a hidden field for the same
purpose.

<%

   if Request("txtMYHIDDENFIELD") = "1" then
    ' the code you have just mentioned.
   else
    ' show no results or a blank page.
   end if

%>
Oops...Sorry. Missed that in your post. - Asked By Robbe Morris on 21-May-01 10:05 PM
...Just curious.
let me try to check it - Asked By Imran Khurshid on 18-Jul-14 01:18 PM
i'll let u know if it does'nt work
Ok... - Asked By Robbe Morris on 18-Jul-14 01:18 PM
...I'm off to bed for the night.
plz help where to insert code - Asked By Imran Khurshid on 21-May-01 11:43 PM
u've told me the following code to add in the track.asp
<%

   if Request.QueryString("POST") = "1" then
    ' the code you have just mentioned.
   else
    ' show no results or a blank page.
   end if

%>
Please let me know or just add the above code in following track.asp page. i would be so greatful for this act of
kindness.
track.asp code......
<%@ LANGUAGE="VBSCRIPT" %>
<html>
<head>

<title>Search Results!</title>
</head>

<body>
<%

Dim SqlJunk


Set dbGlobalWeb = Server.CreateObject("ADODB.Connection")
dbGlobalWeb.Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\creativepk\db\trackingold.mdb"))

SqlJunk = "SELECT * FROM customer"

If Request.Form("TypeSearch") = "BLNUMBER" Then
	SqlJunk = SqlJunk & " WHERE BLNUMBER LIKE '" & Request.Form("DaInBox") & "'"
End If

Set rsGlobalWeb = Server.CreateObject("ADODB.Recordset")
rsGlobalWeb.Open SqlJunk, dbGlobalWeb, 3,3


%>
<%
If rsGlobalWeb.BOF and rsGlobalWeb.EOF Then%>

<h2 align="center">We did not find a match!</h2>
<%Else%>


<%If Not rsGlobalWeb.BOF Then%>


<BR> 
<BR> 
<BR> 
<BR> 
<center><h2>Here are the results of your search:</h2></center>
<table BORDER="1" width="100%" cellpadding="3">
  <tr>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">BL NUMBER </font></th>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">CONNECTING VESSEL </font></th>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">ETD </font></th>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">ETA </font></th>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">FINAL DESTINATION </font></th>
    <th bgcolor="#003366"><font face="Arial" color="#FFFFFF">DELIVERY AGENT </font></th>
  </tr>
<%
	Do While Not rsGlobalWeb.EOF
	%>
  <tr>
    <td><%=rsGlobalWeb("BLNUMBER")%> 

</td>
    <td><%=rsGlobalWeb("CONNECTINGVESSEL")%>
</td>
    <td><%=rsGlobalWeb("ETD")%>
</td>
    <td><%=rsGlobalWeb("ETA")%>
<td><%=rsGlobalWeb("FINALDESTINATION")%>
</td>
<td><%=rsGlobalWeb("DELIVERYAGENT")%>
</td>
</td>
<% rsGlobalWeb.MoveNext
	Loop
	%>
</table>
<%End If%>
<%End If%>
<%
rsGlobalWeb.Close
dbGlobalWeb.Close
%>
</body>
</html>
Everything starting from... - Asked By Robbe Morris on 22-May-01 12:00 PM
...dim SQLJunk

 to dbGlobalWeb.Close

 should go inside the IF statement for
 
 if Request.Querystring("POST") = "1" then
  ' you code goes here.
 else

 end if