Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ASP question?

Status
Not open for further replies.

Phailak

Programmer
Apr 10, 2001
142
CA
Hail,

I just started to use ASP. I'm used to VB so this is what I want to do. When a user clicks on a button, I want to write a response on the page by retrieving data from a table. I figured out how to retrieve the data with the following:

<%
sql=&quot;select * from Players&quot;
Set OBJdbConnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
OBJdbConnection.Open &quot;Glad&quot;
Set RS=OBJdbConnection.Execute(sql)
%>
<%=RS(&quot;Password&quot;)%>
<%
OBJdbConnection.Close
%>

But what I don't understand is how can I launch this when the user clicks on my button??? I tried to put the above script into the following:

<SCRIPT LANGUAGE=VBScript RUNAT=Server>
<%
sql=&quot;select * from Players&quot;
Set OBJdbConnection = Server.CreateObject(&quot;ADODB.Connection&quot;)
OBJdbConnection.Open &quot;Glad&quot;
Set RS=OBJdbConnection.Execute(sql)
%>
<%=RS(&quot;Password&quot;)%>
<%
OBJdbConnection.Close
%>
End Sub
</SCRIPT>

Now I know that is wrong, but can someone maybe point me in the right direction?

Phailak
 
Put this in a file called tt.asp and run it:


<%@ Language=VBScript %>
<%
dim sql, conn, cName
Response.Write &quot;<html><form name=frmTT method=post action=tt.asp>&quot;
if Request.Form(&quot;btnOne&quot;) <> &quot;&quot; then
sql = &quot;select top 1 password from players&quot;
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;<type your connection string;>&quot;
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.Open sql, Conn
if not rs.EOF then
cName = rs(0)
else
cName = &quot;No records in database&quot;
end if
rs.Close
conn.Close
set conn = nothing
set rs = nothing
end if
Response.Write &quot;<input type=submit name=btnOne value=ClickMe><br><br>&quot;
Response.Write cName & &quot;</form></html>&quot;
%>



this is just one way of doing it!

br
Gerard
(-:

Better a known bug then a new release.
 
Doesn't work, I get following error:

Microsoft VBScript compilation error '800a03ea'

Syntax error

/ASPSamp/Gladiators/tt.asp, line 4

Response.Write &quot;<html><form name=frmTT method=post
---------------^

It's probably just syntax error...

Phailak
 
i hope

action=tt.asp>&quot;

is not on a seperate line?the complete response.write line did not fit on the narrow Tek-Tips screen, so it was wrapped.

A multiline statement would be:

Response.Write &quot;<html><form name=frmTT &quot; &_
&quot;method=post &quot; &_
&quot;action=tt.asp>&quot;






br
Gerard
(-:

Better a known bug then a new release.
 
Hail,

Hahaha! Ok that was right, let's just keep this between us :eek:)

I guess I'm just not used to the syntax yet, thx a lot though

Phailak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top