FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


survey Insert in Php





yule
And N't Kick For Cookie

survey.php (code in spanish)
PHP:
Code:

<?
$servidor = "localhost";
$usuario = "";
$password = "";
$base_de_datos = "encuesta";
$conextar=mysql_connect ($direccion,$usuario,$password);
mysql_select_db($base_de_datos);
$sqlupdate = "UPDATE encuestas SET valor$voto = valor$voto+1, total = total+1";
mysql_query($sqlupdate,$conextar);
$sql = "SELECT * FROM encuestas ORDER BY idencuesta desc LIMIT 1";
$resultados = mysql_query($sql,$conextar);
$row = mysql_fetch_array($resultados);
?>
<script type="text/javascript" language="JavaScript">
function resultados(){
window.open("resultados.php",""," toolbar=0,location=0,directories=0,status=0,menuba
r=0,scrollbars=0,resizable=0,width=320,height=200");
}
</script>
<form name="form1" method="post" action="<?= $PHP_SELF?>">
<table width="256" border="0" align="center" cellpadding="0" cellspacing="0" class="forumline">
<tr valign="baseline">
<td colspan="2" class="row1">
<?=$row['pregunta']; ?>
<br>
</td>
</tr>
<tr>
<td width="110">
<?=$row['respuesta1'];?>
</td>
<td width="146"><input type="radio" name="voto" value="1">
</td>
</tr>
<tr>
<td>
<?=$row['respuesta2'];?>
</td>
<td><input type="radio" name="voto" value="2"></td>
</tr>
<tr>
<td>
<?=$row['respuesta3'];?>
</td>
<td><input type="radio" name="voto" value="3"></td>
</tr>
<tr align="center">
<td height="20" colspan="2"><input type="submit" class="post"name="Submit" value="Votar" onClick=window.open("resultados.php",""," toolbar=0,location=0,directories=0,status=0,menuba
r=0,scrollbars=0,resizable=0,width=320,height=200");
}></td>
</tr>
</table>
<p>&nbsp;</p></form>
results.php (code in Spanish) :S
PHP:


Code:
<html>
<head>
<title>Resultados de la encuesta</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
body {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
background-color: #FFFFDD;
}
td {
font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10px;
}
-->
</style>
</head>
<body>
<?
$servidor = "localhost";
$usuario = "";
$password = "";
$base_de_datos = "encuesta";
$conextar=mysql_connect ($direccion,$usuario,$password);
mysql_select_db($base_de_datos);
//$sqlupdate = "UPDATE encuestas SET valor$voto = valor$voto+1, total = total+1";
//mysql_query($sqlupdate,$conextar);
$sql = "SELECT * FROM encuestas ORDER BY idencuesta desc LIMIT 1";
$resultados = mysql_query($sql,$conextar);
$row = mysql_fetch_array($resultados);
$res1= round ($row['valor1']*100/$row['total'],2);
$res2= round ($row['valor2']*100/$row['total'],2);
$res3= round ($row['valor3']*100/$row['total'],2);
?>
<p>Resultados parciales de la encuesta</p>
<?=$row['pregunta']; ?><br>
<br>
<TABLE WIDTH="300" BORDER="1" ALIGN="center" BORDERCOLOR="#3097A3">
<TR>
<TD WIDTH="100"><?=$row['respuesta1']; ?></TD>
<TD WIDTH="*"><IMG HEIGHT="15" WIDTH="<?=$row["valor1"]*100/$row["total"]?>%" SRC="encuesta/barra.gif"></TD>
<TD ALIGN="center" WIDTH="70"><? echo $res1."%";?> </TD>
</TR>
<TR>
<TD WIDTH="100" ><?=$row['respuesta2']; ?></TD>
<TD WIDTH="*"><IMG HEIGHT="15" WIDTH="<?=$row["valor2"]*100/$row["total"]?>%" SRC="encuesta/barra.gif"></TD>
<TD ALIGN="center" WIDTH="70"><? echo $res2."%";?> </TD>
</TR>
<TR>
<TD WIDTH="100"><?=$row['respuesta3']; ?></TD>
<TD WIDTH="*"><IMG HEIGHT="15" WIDTH="<?=$row["valor3"]*100/$row["total"]?>%" SRC="encuesta/barra.gif"></TD>
<TD ALIGN="center" WIDTH="70"><? echo $res3."%";?> </TD>
</TR>
</TABLE>
<form name="form1" method="post" action="">
<div align="center">
<p>
<input type="submit" name="Submit" value="Cerrar Ventana" onclick="window.close();">
</p>
<p>&nbsp; </p>
</div>
</form>
</body>
</html>
RA
Why does nobody use [code][/code] tags in this forum? It should be required for posts containing source code to be replied to.
charliehk
It would be nice if there is a trasnlated version, since some names are difficult to understand! Question
mathiaus
code tags added by request
*mathiaus agrees with the comment about the language issue!*
Related topics
[php scripts ] phpweather&email
E-Cards with PHP & MySQL
What do you use to make your page layout?
i need this
Websites hacked/defaced on Server 2
php and am lost...
How to create online form submission using phpmyadmin Sql
.html or .php?
Does mySQL support BLOB? How?
Psychological Survey
A variable number of inputs for PHP to insert MYSQL
if statement
PHP/MySQL Dropdown value, and insert into database
PHP MYSQL INSERT
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.