www.webdeveloper.com
Results 1 to 5 of 5

Thread: Help me to Show the output below the form

  1. #1
    Join Date
    Dec 2005
    Posts
    12

    Help me to Show the output below the form

    Dear Friends
    Hi
    I am new to this forum...
    But with a problem...
    I am unable to show the output of a seach below the form.
    I have made two pages One for the form and another for the Qeary and output and connected but unable to show the output below d form..

    I am writing the code below

    Form page:

    <html>
    <body>
    <table align="center" height="50%" cellspacing="2%">
    <tr ><td colspan=3 align="center"><h3><u>CONTACT</u></h3></td></tr>

    <form method="post" action="process.asp">

    <tr><td>CompanyName</td><td><input type="text" name="Companyname"></td></tr>

    <tr><td>ContactName</td><td><input type="text" name="Contactname"></td></tr>

    <tr><td>Country</td><td><input type="text" name="country"></td></tr>

    <tr><td colspan=3 align="center"><input type="submit" value="Search"></td></tr>


    </table>
    </form>
    </body>
    </html>


    Asp page:

    <%
    company=Request.Form("companyname")
    contact=Request.Form("contactname")
    countri=Request.Form("country")

    cheak=company+contact+countri
    Blank=""
    If cheak = Blank Then
    Response.Write("All the fields are Blank")

    Else

    %>
    <html>
    <body>
    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.provider="Microsoft.jet.OLEDB.4.0"
    conn.open "c:/amit/database/northwind.mdb"
    set rs=Server.CreateObject("ADODB.recordset")

    If company+contact="" Then
    sql="SELECT Companyname, Contactname, Country FROM Customers WHERE country LIKE '"&countri&"'"
    Else
    sql="SELECT Companyname, Contactname, Country FROM Customers WHERE (companyname LIKE '"&company&"' OR contactname LIKE '"&contact&"')"
    End IF

    rs.open sql,conn
    %>
    <table border="1" width="100%" valign="bottom" cellpadding="0" Cellspacing="5" bgcolor="#boc4de">
    <tr align="left" bgcolor="7fff00">
    <%For Each x in rs.fields%>
    <td><%Response.Write(X.name)%></td>
    <%Next%>
    </tr>
    <%
    I=1
    Do until rs.EOF

    a=I mod 2
    If a=0 Then

    %>
    <tr align="left" bgcolor="00ffff">
    <%for each x in rs.fields%>
    <td><% Response.Write(X.value)%></td>
    <%Next%>
    </tr>
    <%Else%>

    <tr align="left" bgcolor="ffff00">
    <%for each x in rs.fields%>
    <td><% Response.Write(X.value)%></td>
    <%Next%>
    </tr>
    <%
    End If
    I=I+1
    rs.MoveNext
    Loop
    rs.close
    conn.close
    set rs=nothing
    set conn=nothing
    %>
    </table>
    </body>
    </html>
    <%End if%>


    If anyone can help me i would be greatful to him/her.
    Waiting for ur reply

  2. #2
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    see what you think to this...
    Code:
    <html>
    <body>
    
    <%
    
    company = Request.Form("companyname") & ""
    contact = Request.Form("contactname") & ""
    country = Request.Form("country") & ""
    
    %>
    
    <form method="post" action="process.asp">
    	<table align="center" cellspacing="2%">
    		<tr>
    			<td colspan=2 align="center"><h3><u>CONTACT</u></h3></td>
    		</tr>
    		<tr>
    			<td>CompanyName</td>
    			<td><input type="text" name="Companyname" value="<%=server.htmlencode(company)%>"></td>
    		</tr>
    		<tr>
    			<td>ContactName</td>
    			<td><input type="text" name="Contactname" value="<%=server.htmlencode(contact)%>"></td>
    		</tr>
    		<tr>
    			<td>Country</td>
    			<td><input type="text" name="country" value="<%=server.htmlencode(country)%>"></td>
    		</tr>
    		<tr>
    			<td colspan=2 align="center"><input type="submit" value="Search"></td>
    		</tr>
    	</table>
    </form>
    
    <%
    
    'dbpath = "c:\amit\database\northwind.mdb"
    dbpath = "C:\Program Files\Microsoft Office\Office10\Samples\northwind.mdb"
    
    connstr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & dbpath & "';"
    
    set rs = Server.CreateObject("ADODB.recordset")
    
    if company <> "" then
    	sql = " companyname like '" & replace(company,"'","''") & "%'"
    	sqldelim = " and "
    end if
    if contact <> "" then
    	sql = sql & sqldelim & " contactname like '" & replace(contact,"'","''") & "%'"
    	sqldelim = " and "
    end if
    if country <> "" then
    	sql = sql & sqldelim & " country like '" & replace(country,"'","''") & "%'"
    end if
    if sql <> "" then
    	sql = " where " & sql
    end if
    sql = "SELECT Companyname, Contactname, Country FROM Customers " & sql
    
    rs.open sql,connstr,1,3
    
    %>
    
    <table border="1" width="100%" valign="bottom" cellpadding="2" Cellspacing="2" bgcolor="#boc4de">
    	<tr align="left" bgcolor="#7fff00">
    		<%
    		For Each x in rs.fields
    			response.write "<td>" & X.name & "</td>"
    		Next
    		%>
    	</tr>
    	<%
    
    	I = 1
    	Do until rs.EOF
    
    		If i mod 2 = 0 Then
    			bgcolor = "#ffff00"
    		else
    			bgcolor = "#00ffff"
    		end if
    
    		%>
    		<tr align="left" bgcolor="<%=bgcolor%>">
    			<%
    			for each x in rs.fields
    				response.write "<td>" & X.value & "</td>"
    			Next
    			%>
    		</tr>
    		<%
    		I = I + 1
    		rs.MoveNext
    	Loop
    	rs.close
    
    	%>
    </table>
    
    </body>
    </html>

  3. #3
    Join Date
    Dec 2005
    Posts
    12

    Smile

    Thanks Russel i am really very greatful to u...
    I am a new learner...
    I am unable to get about some syntex u have used i m marKing those with color . i would be glad If u can explain or can suggest me some readings ...

    <html>
    <body>

    <%

    company = Request.Form("companyname") & ""
    contact = Request.Form("contactname") & ""
    country = Request.Form("country") & ""

    Data Source='" & dbpath & "';"

    if company <> "" then
    sql = " companyname like '" & replace(company,"'","''") & "%'"
    sqldelim = " and "

  4. #4
    Join Date
    Dec 2003
    Location
    England, UK
    Posts
    432
    Code:
    company = Request.Form("companyname") & ""
    putting & "" on the end of this statement just makes sure that the company variable is of a string subtype rather than anything else. not sure if its needed really but its nice to make sure rather than have to track down a bug somewhere else in the code later on.

    Code:
    'dbpath = "c:\amit\database\northwind.mdb"
    dbpath = "C:\Program Files\Microsoft Office\Office10\Samples\northwind.mdb"
    connstr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source='" & dbpath & "';"
    all we're doing here is creating a connection string for ado. you can tell it various things, like what type of database it is, where it is, etc. ado then uses this to connect to your database. the syntax for the string is an ado thing, as far as vbscript is concerned it's just a string. there are more examples at http://www.connectionstrings.com/.

    Code:
    if company <> "" then
    this just says if the company variable doesn't contain an emtpy string then... the reason for it is because you don't want to add that part of the sql where clause if you don't have anything to search for.

    Code:
    sql = " companyname like '" & replace(company,"'","''") & "%'"
    putting the replace function around the variable is to prevent sql injection. i.e. if a user typed a ' into one of the boxes without the replace, then it would end the string literal and the sql statement could then be changed drastically. effectively giving users of your site free access to your database.

    not sure about anywhere that you can read up on this sort of thing. i've still not found anything particularly useful like that. best bet is to ask questions in a forum like this. and make sure you've got the script documentation from here, http://msdn.microsoft.com/library/de...ist/webdev.asp, this'll answer a lot of your questions about syntax and what functions are available.

  5. #5
    Join Date
    Dec 2005
    Posts
    12
    Thanx Russel
    I am really great ful to u ...
    And alwys pray God to help u...
    Take Care
    Love
    Amit

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles