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]<?php
require("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]<?php
require("config.php");
mysql_query("UPDATE sonda SET tot_{$POST[a]} = tot{$_POST[a]} + 1");
header("Location: results.php");
?>[/php]results.php
[php]<?php
require("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.