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..
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
<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>
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 "
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.
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.
Bookmarks