- Home
- Categorie
- Coding e Sistemistica
- Coding
- Aiuto per sondaggio PHP
-
Aiuto per sondaggio PHP
Salve, io è da tanto che provo a fare funzionare un sondaggio in php ma non riesco a fargli salvare i dati nel database e a farglieli richiamare. vi posto l'intero script:
config.php
[php]<?php$mysql[host] = "localhost";
$mysql[user] = "root";
$mysql[pass] = "";
$mysql[name] = "dbsond";$question = "Come vi sembra il nostro sito?";
$answers = array("Stupendo", "Bello", "Brutto", "Schifo");@mysql_connect($mysql[host], $mysql[user], $mysql[pass]);
@mysql_select_db($mysql[name]);
?>[/php]index.php
[php]<?phprequire("config.php");
echo '<form action="vote.php" method="post">';
echo "<strong>{$question}</strong><br><br>";for ($i = 0; $i <= count($answers) - 1; $i++)
{
echo "<input type="radio" name="a" value=' . ($i + 1) . '>{$answers*}<br>";
}echo '<br><input type="submit" value="Vota">';
echo '<a href="results.php">Risultati</a>';
echo '</form>';
?>[/php]vote.php
[php]<?phprequire("config.php");
mysql_query("UPDATE sonda SET tot_{$POST[a]} = tot{$_POST[a]} + 1");
header("Location: results.php");?>[/php]results.php
[php]<?phprequire("config.php");
$query = @mysql_query("SELECT * FROM sonda");
$result = @mysql_fetch_array($query);echo "<strong>{$question}</strong><br><br>";
for ($x = 1; $x <= count($answers); $x++){
$total = $total + $result[tot_ . $x];
}for ($i = 1; $i <= count($answers); $i++)
{
@$percent = $result[tot_ . $i] / $total;
$percent = $percent * 100;
$percent = number_format($percent, 1);
echo "" . $answers[$i - 1] . " (<strong>{$percent}%</strong>)<br />";
}?>[/php]
qualcuno sa perchè non vengono aggiunti i dati al database e neanche ripresi?
Ringrazio in anticipo.
-
a scusate mi sono dimenticato il file della tabelle che cè nel database:
install.php
[PHP]<?phprequire("config.php");
mysql_query("CREATE TABLE sonda (
id INT( 11 ) NOT NULL AUTO_INCREMENT ,
tot_1 VARCHAR( 255 ) DEFAULT 0 NOT NULL ,
tot_2 VARCHAR( 255 ) DEFAULT 0 NOT NULL ,
tot_3 VARCHAR( 255 ) DEFAULT 0 NOT NULL ,
tot_4 VARCHAR( 255 ) DEFAULT 0 NOT NULL ,
INDEX (id));");
mysql_query("INSERT INTO sonda VALUES ('',0,0,0,0)");
echo "Linstallazione è avvenuta con successo!<br />";
?>[/PHP]