Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Alexandre Di Salvo

Gerando formulários em ASP

Recommended Posts

Olá a todos...

 

Estou desenvolvendo um sisteminha que gera formulários... Na verdade seriam perguntas respondidas por certas pessoas e que seriam gravadas num BD. A priori estou me preocupando com a programação em ASP.

 

Peguei uns exemplos de survey na internet.

 

Bom... mas eu consigo fazer uma pergunta com botoes rádio, por exemplo:

 

- Sexo:

( ) Masculino ( ) Feminino

 

Mas quando a pergunta envolve um campo de texto eu não consigo. Por exemplo:

 

- Nome: ________________________

 

Daí gravar esse valor no banco de dados.

 

Alguem ai pode me ajudar??

Compartilhar este post


Link para o post
Compartilhar em outros sites

você tb pode gerar relatorios atraves do ASP Report Wizard, entre outros, mas pelo k você postou você terá um form e ira recuperar os dados...

 

imagine um form, assim:

 

<form name="form1" method="post" action="incluir_action_treina.asp"> 
<table width="99%" border="0" bordercolor="#e6e6e6"> <tr> <td><b><font color="#336699" size="1" face="Verdana, Arial, Helvetica, sans-serif">Entre 
com o login: <input type="text" name="login" size="12" maxlength="12"> </font></b></td></tr> 
<tr> <td height="12" bordercolor="0"><b><font color="#336699" size="1" face="Verdana, Arial, Helvetica, sans-serif">Entre 
com sua senha: <input type="password" name="senha" size="8" value="" maxlength="8"> 
</font></b></td></tr> <tr> <td bordercolor="0"><b><font color="#336699" size="1" face="Verdana, Arial, Helvetica, sans-serif">Entre 
com o email: <input type="text" name="email" size="48" maxlength="48"> </font></b></td></tr> 
<tr> <td bordercolor="0"> <div align="center"> 
				<input type="image" border="0" name="imageField" src="imgs/enviar.gif" width="87" height="22"> 
</div></td></tr> </table></form></td></tr> </table>

você recuper os dados e dá um insert no BD

<% 'incluir_action.asp => fazer a inclusao no BD, antes fazendo uma verificaçao
   'no BD através de SQL Select if not rs.eof then
   'redireciono para incluir_form.asp?msgeof=1 else
   'incluo no bd atraves da SQL Insert e redireciono para adiministraçao.asp?msg=1
   'e lá receberá um mensagem de sucesso
   
   Option explicit
   'declaro as var
   dim varlogin, varemail, varsenha, conexao, conDBQ, constring, rsselect, SQLselect, rsinsert, SQLinsert
   'recupero todos os dados
   varlogin=trim(request.form("login"))
   varsenha=trim(request.form("senha"))
   varemail=trim(request.form("email"))
   'crio a conexao
   %>
   <!--#include file="conn/conexao1.asp"-->
   <% 'abrir a conexao
   call abreconexao
   'crio o rsselect para verificar se os dados jah estaun cadastrados
   set rsselect=server.createobject("ADODB.Recordset")
   'crio o SQLselect
   SQLselect="SELECT login FROM login WHERE login='"&varlogin&"'"
   rsselect.open SQLselect,conexao,1,3
   if not rsselect.eof then
   		response.redirect("incluir_form_treina.asp?msgeof=1")
		set rsselect=nothing
   else	
   		'crio o rsinsert para inseiri os dados no bd
   		 set rsinsert=server.createobject("ADODB.Recordset")
		'crio o SQLinsert pra incluir no bd
		SQLinsert="INSERT INTO login(login,senha,email) values('"&varlogin&"','"&varsenha&"','"&varemail&"')"
		rsinsert.open SQLinsert,conexao,1,3
		response.redirect("administracao_treina.asp?msg=1")
		set rsinsert=nothing
	end if 
	call fechaconexao %>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Jovem, poste ae como esta o seu code.

Opa, claro claro :)

 

Esse código é da página eu eu gero ''uma pergunta''

 

<div align="center">
<table border="1" class="nortxtv8" cellpadding="3" cellspacing="0" width="600" style="border-collapse: collapse" bordercolor="#000000">
	<tr>
		<td colspan="2" bgcolor="#ADD8E6"><b>Cadastrar nova pergunta </b> <a href="?act=logout"><img src="adm_img/logout.gif" name="new" border="0" alt="Logout" WIDTH="36" HEIGHT="16" align="absmiddle"></a></td>
	</tr>
	<form name="formPoll" method="post" action="admin-update.asp?sub=new">
	<tr>
		<td>
			<table width="100%" border="0" cellspacing="0" cellpadding="1" class="nortxtv8">
			  <tr>
				<td width="100">Título</td>
				<td><input type="text" name="title" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 1</td>
				<td><input type="text" name="a1" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 2</td>
				<td><input type="text" name="a2" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 3</td>
				<td><input type="text" name="a3" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 4</td>
				<td><input type="text" name="a4" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 5</td>
				<td><input type="text" name="a5" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 6</td>
				<td><input type="text" name="a6" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 7</td>
				<td><input type="text" name="a7" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 8</td>
				<td><input type="text" name="a8" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 9</td>
				<td><input type="text" name="a9" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 10</td>
				<td><input type="text" name="a10" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Data início</td>
				<td><input type="text" name="d_s" size="20" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Data fim </td>
				<td><input type="text" name="d_e" size="20" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100"> </td>
				<td><input type="image" border="0" name="Submit" src="adm_img/submit.gif" width="40" height="16"></td>
			  </tr>
			</table>
		</td>
	</tr>
	</form>
</table>
</div>

Compartilhar este post


Link para o post
Compartilhar em outros sites

como está sendo passado do asp par ao banco, posta ai o codigo ASP e diga tbm quais a propriedades da coluna do banco de dados!

Compartilhar este post


Link para o post
Compartilhar em outros sites

como você esta recebendo (dando um request nos dados) e fazendo o INSERT

qual o code de admin-update.asp, mas você poe se basear no exemplo que postei,simples

e objetivo

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eis o código de toda minha página que cadastra as perguntas:

 

<%@ Language=VBScript %>
<%
'wrong login ...?
if session("loginSuccessful") <> "yes" then Response.Redirect ("login.asp")

if Request.QueryString("act") = "logout" then 
	session("loginSuccessful") = ""
	Response.Redirect ("login.asp")
end if
%>
<html>
<head>
<meta NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<link rel="stylesheet" href="poll.css" type="text/css">
<style type="text/css">
<!--
.form {font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 8pt; font-style: normal; font-weight: normal; font-variant: normal; color: #000000; text-decoration: none}
-->
</style>
</head>
<body>
<%
dim SQL, rs, cn, id

id = Request.QueryString("id")

Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & server.MapPath ("../fpdb/poll.mdb")

if Request.QueryString("sub") = "addnew" then addnew()
if Request.QueryString("sub") = "edit" then edit()
if Request.QueryString("sub") = "edit_add" then edit_add()

SQL = "SELECT * FROM title ORDER BY id ASC"
set rs = cn.Execute(SQL)
%>
<%if session("adminRights") = 1 then%>

<div align="center">
<table border="1" class="nortxtv8" cellpadding="3" cellspacing="0" width="600" style="border-collapse: collapse" bordercolor="#000000">
	<tr>
		<td colspan="2" bgcolor="#ADD8E6">
		<a href="admin-poll.asp?sub=addnew"><img src="adm_img/new.gif" name="new" border="0" alt="Add new poll" WIDTH="61" HEIGHT="16" align="absmiddle"></a> 
		<a href="admin-users.asp"><img src="adm_img/users.gif" name="new" border="0" alt="Edit users" WIDTH="36" HEIGHT="16" align="absmiddle"></a>
		<a href="?act=logout"><img src="adm_img/logout.gif" name="new" border="0" alt="Logout" WIDTH="36" HEIGHT="16" align="absmiddle"></a>
		</td>
	</tr>
	<tr>
		<%
		if not rs.eof then
		do
		%>
	<tr>
		<td><%="Pergunta id: <span><b>" & rs("id") & "</b></span> - " & rs("title")%></td>
		<td width="125" align="center">
		<%if rs("active") then %>
		<a href="admin-update.asp?sub=inact&id=<%=rs("id")%>"><img src="adm_img/active.gif" align="absmiddle" name="active" border="0" alt="The poll is active - set to inactive" WIDTH="36" HEIGHT="16"></a>
		<%else%>
		<a href="admin-update.asp?sub=act&id=<%=rs("id")%>"><img src="adm_img/inact.gif" align="absmiddle" name="inact" border="0" alt="The poll is inactive - set to active" WIDTH="36" HEIGHT="16"></a>
		<%end if%>
		<a href="admin-poll.asp?sub=edit&id=<%=rs("id")%>"><img src="adm_img/edit.gif" align="absmiddle" name="edit" border="0" alt="Edit poll" WIDTH="36" HEIGHT="16"></a>
		<a href="admin-update.asp?sub=del&id=<%=rs("id")%>"><img src="adm_img/delete.gif" align="absmiddle" name="delete" border="0" alt="Delete poll" WIDTH="36" HEIGHT="16"></a></td>
	</tr>
		<%
		rs.movenext
		loop until rs.eof
		else
		%>
			  <td>Não existem Perguntas! 
				  <%end if%>
	</tr>
</table>
</div>
	
<%
elseif session("adminRights") = 2 then

	addnew()
	
end if
%>

<%sub addnew()%>

<div align="center">
<table border="1" class="nortxtv8" cellpadding="3" cellspacing="0" width="600" style="border-collapse: collapse" bordercolor="#000000">
	<tr>
		<td colspan="2" bgcolor="#ADD8E6"><b>Cadastrar nova pergunta </b> <a href="?act=logout"><img src="adm_img/logout.gif" name="new" border="0" alt="Logout" WIDTH="36" HEIGHT="16" align="absmiddle"></a></td>
	</tr>
	<form name="formPoll" method="post" action="admin-update.asp?sub=new">
	<tr>
		<td>
			<table width="100%" border="0" cellspacing="0" cellpadding="1" class="nortxtv8">
			  <tr>
				<td width="100">Título</td>
				<td><input type="text" name="title" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 1</td>
				<td><input type="text" name="a1" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 2</td>
				<td><input type="text" name="a2" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 3</td>
				<td><input type="text" name="a3" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 4</td>
				<td><input type="text" name="a4" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 5</td>
				<td><input type="text" name="a5" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 6</td>
				<td><input type="text" name="a6" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 7</td>
				<td><input type="text" name="a7" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 8</td>
				<td><input type="text" name="a8" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 9</td>
				<td><input type="text" name="a9" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Resposta 10</td>
				<td><input type="text" name="a10" size="40" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Data início</td>
				<td><input type="text" name="d_s" size="20" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100">Data fim </td>
				<td><input type="text" name="d_e" size="20" class="nortxtv8"></td>
			  </tr>
			  <tr>
				<td width="100"> </td>
				<td><input type="image" border="0" name="Submit" src="adm_img/submit.gif" width="40" height="16"></td>
			  </tr>
			</table>
		</td>
	</tr>
	</form>
</table>
<br />
</div>

<%end sub%>

<%
sub edit()
dim an_no, show
dim e_start, e_end
show = 1

an_no = 1

SQL = "SELECT * FROM title, vote WHERE id=" & id & " AND id=poll_id"
set rs = cn.Execute(SQL)

'if there is no answers in the database
if rs.eof then
	SQL = "SELECT * FROM title WHERE id=" & id
	set rs = cn.Execute(SQL)
	show = 0
end if

e_start = rs("expiration_start")
e_end = rs("expiration_end")

%>

<div align="center">
<table border="1" class="nortxtv8" cellpadding="3" cellspacing="0" width="600" style="border-collapse: collapse" bordercolor="#000000">
	<tr>
		<td colspan="2" bgcolor="#ADD8E6"><b>Editar Pergunta </b> <a href="?act=logout"><img src="adm_img/logout.gif" name="new" border="0" alt="Logout" WIDTH="36" HEIGHT="16" align="absmiddle"></a></td>
	</tr>
	<form name="formPoll" method="post" action="admin-update.asp?sub=edit&id=<%=id%>">
	<tr>
		<td>
			<table width="100%" border="0" cellspacing="0" cellpadding="1" class="nortxtv8">
			  <tr>
				<td width="100">Título Pergunta</td>
				<td><input type="text" name="title" size="40" class="nortxtv8" value="<%=rs("title")%>"> Pergunta id: <font color="#FF0000"><b><%=rs("id")%></b></font>
				  Todos os votos: <b><%=rs("votes")%></b></td>
			  </tr>
			  <%
			  if not show = 0 then
			  do
			  %>			  
			  <tr>
				<td width="100">Resposta <%=an_no%></td>
				<td>
				<input type="hidden" name="h<%=an_no%>" size="40" class="nortxtv8" value="<%=rs("answer_id")%>">
				<input type="text" name="a<%=an_no%>" size="40" class="nortxtv8" value="<%=rs("answer")%>"> Resp. id: <font color="#FF0000"><b><%=rs("answer_id")%></b></font>
				  Votos: <b><%=rs("no_votes")%></b> 
				<a href="admin-update.asp?sub=del_answ&answ_id=<%=rs("answer_id")%>&id=<%=rs("id")%>">
				<img src="adm_img/delete.gif" align="absmiddle" name="delete" border="0" alt="Delete poll" WIDTH="36" HEIGHT="16">
				</a></td>
			  </tr>
			  <%
			  an_no = an_no + 1
			  rs.movenext
			  loop until rs.eof
			  end if
			  %>
			  <tr>
				<td width="100">Data início </td>
				<td><input type="text" name="d_s" size="20" class="nortxtv8" value="<%=e_start%>"></td>
			  </tr>
			  <tr>
				<td width="100">Data fim </td>
				<td><input type="text" name="d_e" size="20" class="nortxtv8" value="<%=e_end%>"></td>
			  </tr>
			  <tr>
				<td width="100"> </td>
				<td>
				<input type="hidden" name="no_answers" size="40" class="nortxtv8" value="<%=an_no - 1%>">
				<input type="image" border="0" name="Submit" src="adm_img/submit.gif" width="40" height="16" alt="Update database">
				<a href="admin-poll.asp?sub=edit_add&id=<%=id%>"><img border="0" name="add" src="adm_img/add_answ.gif" width="50" height="16" alt="Add one answer"></a>
				</td>
			  </tr>
			</table>
		</td>
	</tr>
	</form>
</table>
</div>

<%
end sub
%>

<%
sub edit_add()
dim an_no, show
show = 1

an_no = 1

SQL = "SELECT * FROM title, vote WHERE id=" & id & " AND id=poll_id"
set rs = cn.Execute(SQL)

'if there is no answers in the database
if rs.eof then
	SQL = "SELECT * FROM title WHERE id=" & id
	set rs = cn.Execute(SQL)
	show = 0
end if

e_start = rs("expiration_start")
e_end = rs("expiration_end")
%>

<div align="center">
<table border="1" class="nortxtv8" cellpadding="3" cellspacing="0" width="600" style="border-collapse: collapse" bordercolor="#000000">
	<tr>
		<td colspan="2" bgcolor="#ADD8E6"><b>Editar Pergunta </b> <a href="?act=logout"><img src="adm_img/logout.gif" name="new" border="0" alt="Logout" WIDTH="36" HEIGHT="16" align="absmiddle"></a></td>
	</tr>
	<form name="formPoll" method="post" action="admin-update.asp?sub=edit_add&id=<%=id%>">
	<tr>
		<td>
			<table width="100%" border="0" cellspacing="0" cellpadding="1" class="nortxtv8">
			  <tr>
				<td width="100">Título Pergunta</td>
				<td><b><%=rs("title")%></b>   Perg. id: <font color="#FF0000"><b><%=rs("id")%></b></font>
				  Todos votos : <b><%=rs("votes")%></b></td>
			  </tr>
			  <%
			  if not show = 0 then
			  do
			  %>			  
			  <tr>
				<td width="100">Resposta <%=an_no%></td>
				<td><b><%=rs("answer")%></b>   Resp. id: <font color="#FF0000"><b><%=rs("answer_id")%></b></font>
				  Votos: <b><%=rs("no_votes")%></b>
				</td>
			  </tr>
			  <%
			  an_no = an_no + 1
			  rs.movenext
			  loop until rs.eof
			  end if
			  %>
			  <tr>
				<td width="100">Nova Resposta </td>
				<td>
					<input type="text" name="add_one" size="40" class="nortxtv8">
				</td>
			  </tr>
			  <tr>
				<td width="100"> </td>
				<td>
				<input type="hidden" name="no_answers" size="40" class="nortxtv8" value="<%=an_no - 1%>">
				<input type="image" border="0" name="Submit" src="adm_img/submit.gif" width="40" height="16" alt="Update database">
				</td>
			  </tr>
			</table>
		</td>
	</tr>
	</form>
</table>
</div>

<%
end sub
%>

</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Eis o admin-update.asp:

 

<%@ Language=VBScript %>
<%
'option explicit
'wrong login ...?
if session("loginSuccessful") <> "yes" then Response.Redirect ("login.asp")
dim SQL, cn, rs

Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & server.MapPath ("../fpdb/poll.mdb")

if Request.QueryString("sub") = "new_usr" then new_usr()
if Request.QueryString("sub") = "edit_usr" then edit_usr()
if Request.QueryString("sub") = "del_usr" then del_usr()
if Request.QueryString("sub") = "new" then add_new()
if Request.QueryString("sub") = "act" then act()
if Request.QueryString("sub") = "inact" then inact()
if Request.QueryString("sub") = "edit" then edit()
if Request.QueryString("sub") = "edit_add" then edit_add()
if Request.QueryString("sub") = "del_answ" then del_answ()
if Request.QueryString("sub") = "del" then del()
%>

<%
'add new user
sub new_usr()
dim a, usr_id

'get last user id
SQL = "SELECT * FROM users ORDER BY usr_id DESC"
set rs = cn.Execute(SQL)
usr_id = rs("usr_id") + 1

'get status for new user (1 - admin, 2 - normal user)
if Request.Form("status") = "yes" then
	a = 1
else
	a = 2
end if

'add new user
SQL = "INSERT INTO users ([usr_id],[username],[password],[status],[email]) " & _
	  "VALUES (" & usr_id & ",'" & Request.Form("user") & "','" & Request.Form("pass") & "'," & a & ",'" & Request.Form("email") & "')"
set rs = cn.Execute(SQL)

Response.Redirect("admin-users.asp")

end sub
%>

<%
'update user data
sub edit_usr()
dim a

'get status for user (1 - admin, 2 - normal user)
if Request.Form("status") = "yes" then
	a = 1
else
	a = 2
end if

'update user data
SQL ="UPDATE users SET " & _
	 "[username]='" & Request.Form("user") & _
	 "',[password]='" & Request.Form("pass") & _
	 "',[status]=" & a & ", [email]='" & Request.Form("email") & _
	 "' WHERE usr_id=" & Request.QueryString("id")
set rs = cn.Execute(SQL)

Response.Redirect("admin-users.asp")

end sub
%>

<%
'delete user
sub del_usr()

SQL = "DELETE FROM users WHERE usr_id=" & Request.QueryString("id")
set rs = cn.Execute(SQL)

Response.Redirect("admin-users.asp")

end sub
%>

<%
'add new poll
sub add_new()
dim a, b, poll_id, answ_id
dim email, str

'get last poll id
SQL = "SELECT * FROM title ORDER BY id DESC"
set rs = cn.Execute(SQL)

if not rs.eof then
	poll_id = rs("id") + 1
else
	poll_id = 1
end if

'add poll title
SQL = "INSERT INTO title (id,title,expiration_start,expiration_end) VALUES " & _
	  "(" & poll_id & ",'" & Request.Form("title") & "','" & Request.Form("d_s") & "','" & Request.Form("d_e") & "')"
set rs = cn.Execute(SQL)

'get last answer id
SQL = "SELECT * FROM vote ORDER BY answer_id DESC"
set rs = cn.Execute(SQL)

if not rs.eof then
	answ_id = rs("answer_id")
else
	answ_id = 1
end if

'add answers
a = 1 'for looping through textboxes
b = 1 'for adding answer_id
do

if not Request.Form("a" & a) = "" then
	SQL = "INSERT INTO vote (poll_id,answer_id,answer) VALUES " & _
		  "(" & poll_id & "," & answ_id + b & ",'" & Request.Form("a" & a) & "')"
	set rs = cn.Execute(SQL)
	b = b + 1
end if

a = a + 1
loop until a = 11

'code for sending email to admin users (only admin can set poll to active)
'######### UNCOMENT FOR SENDING EMAIL TO ALL ADMIN USERS WHEN NORMAL USER ADDS NEW POLL #########
'if session("adminRights") = 2 then
	
	'SQL = "SELECT * FROM users WHERE status = 1 ORDER BY usr_id ASC"
	'set rs = cn.Execute(SQL)
	
	'do
	
	'if not email = "" then 
	'	str = "; " & email 
	'end if

	'email = rs("email") & str 

	'rs.movenext
	'loop until rs.eof

	'Set EMail = CreateObject("CDONTS.NewMail") 
	'With EMail
	' .From = "someone@domain.com"
	' .bcc = email 
	' .Subject = "New poll in database"
	' .Body = "Poll title: " & Request.Form("title")
	' .Send 
	'End with 
	'Set EMail = Nothing 

'end if

Response.Redirect("admin-poll.asp")

end sub
%>

<%
'set poll to active
sub act()
dim poll_id

poll_id = Request.QueryString("id")

'set all polls to inactive
SQL = "UPDATE title SET active=False"
set rs = cn.execute(SQL)

'set selected poll to active
SQL = "UPDATE title SET active=True WHERE id=" & poll_id
set rs = cn.execute(SQL)

Response.Redirect("admin-poll.asp")

end sub
%>

<%
'set poll to inactive
sub inact()
dim poll_id

poll_id = Request.QueryString("id")

'set selected poll to inactive
SQL = "UPDATE title SET active=False WHERE id=" & poll_id
set rs = cn.execute(SQL)

Response.Redirect("admin-poll.asp")

end sub
%>

<%
'save edited poll
sub edit()
dim no, i, poll_id

i = 1

'get number of textboxes
no = Request.Form ("no_answers")
'get poll id
poll_id = Request.QueryString ("id")

'update poll title
SQL = "UPDATE title SET title='" & Request.Form ("title") & "', expiration_start='" & Request.Form("d_s") & _
	  "', expiration_end='" & Request.Form("d_e") & "' WHERE id=" & poll_id
set rs = cn.Execute(SQL)

'get all textboxes and update database with edited answers
do
SQL = "UPDATE vote SET answer='" & Request.Form ("a" & i) & "' WHERE answer_id=" & Request.Form ("h" & i)
set rs = cn.Execute(SQL)
i = i + 1
loop until i = no + 1

Response.Redirect("admin-poll.asp?sub=edit&id=" & poll_id)

end sub
%>

<%
'add one answer
sub edit_add()
dim poll_id, answ_id

poll_id = Request.QueryString("id")

'if textbox is empty ...
if not Request.Form("add_one") = "" then

'get last answer id
SQL = "SELECT * FROM vote ORDER BY answer_id DESC"
set rs = cn.execute(SQL)

'set answer id to next number
answ_id = rs("answer_id") + 1

'add answer
SQL = "INSERT INTO vote (poll_id,answer_id,answer) VALUES (" & poll_id & "," & answ_id & ",'" & Request.Form("add_one") & "')"
set rs = cn.execute(SQL)

end if

Response.Redirect("admin-poll.asp?sub=edit&id=" & poll_id)

end sub
%>

<%
'delete poll
sub del_answ()
dim poll_id
'get poll id
poll_id = Request.QueryString ("id")

'delete selected answer
SQL = "DELETE FROM vote WHERE answer_id=" & Request.QueryString("answ_id")
set rs = cn.Execute(SQL)

Response.Redirect("admin-poll.asp?sub=edit&id=" & poll_id)

end sub
%>

<%
'delete poll
sub del()
dim poll_id
'get poll id
poll_id = Request.QueryString ("id")

'delete poll and corresponding answers
SQL = "DELETE FROM title WHERE id=" & poll_id
set rs = cn.Execute(SQL)
SQL = "DELETE FROM vote WHERE poll_id=" & poll_id
set rs = cn.Execute(SQL)

Response.Redirect("admin-poll.asp")

end sub
%>

Vale lembrar que estiou modificando um sistema pré-existente

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.