<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Aiuto per sondaggio PHP]]></title><description><![CDATA[<p dir="auto">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:</p>
<p dir="auto">config.php</p>
<pre><code class="language-php">&lt;?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]);
?&gt;
</code></pre>
<p dir="auto">index.php</p>
<pre><code class="language-php">&lt;?php

require("config.php");


echo '&lt;form action="vote.php" method="post"&gt;';
echo "&lt;strong&gt;{$question}&lt;/strong&gt;&lt;br&gt;&lt;br&gt;";



for ($i = 0; $i &lt;= count($answers) - 1; $i++)

{

echo "&lt;input type=\"radio\" name=\"a\" value=' . ($i + 1) . '&gt;{$answers[$i]}&lt;br&gt;";
}



echo '&lt;br&gt;&lt;input type="submit" value="Vota"&gt;';
echo '&lt;a href="results.php"&gt;Risultati&lt;/a&gt;';
echo '&lt;/form&gt;';
?&gt;
</code></pre>
<p dir="auto">vote.php</p>
<pre><code class="language-php">&lt;?php

require("config.php");


mysql_query("UPDATE sonda SET tot_{$_POST[a]} = tot_{$_POST[a]} + 1");
header("Location: results.php");
 
?&gt;
</code></pre>
<p dir="auto">results.php</p>
<pre><code class="language-php">&lt;?php

require("config.php");


$query = @mysql_query("SELECT * FROM sonda");
$result = @mysql_fetch_array($query);



echo "&lt;strong&gt;{$question}&lt;/strong&gt;&lt;br&gt;&lt;br&gt;";
for ($x = 1; $x &lt;= count($answers); $x++)

{

$total = $total + $result[tot_ . $x];
}



for ($i = 1; $i &lt;= count($answers); $i++)

{

@$percent = $result[tot_ . $i] / $total;
$percent = $percent * 100;
$percent = number_format($percent, 1);
echo "" . $answers[$i - 1] . " (&lt;strong&gt;{$percent}%&lt;/strong&gt;)&lt;br /&gt;";
}

?&gt;
</code></pre>
<p dir="auto">qualcuno sa perchè non vengono aggiunti i dati al database e neanche ripresi?<br />
Ringrazio in anticipo.</p>
]]></description><link>https://dev.connect.gt/topic/142882/aiuto-per-sondaggio-php</link><generator>RSS for Node</generator><lastBuildDate>Sun, 29 Nov 2026 11:34:37 GMT</lastBuildDate><atom:link href="https://dev.connect.gt/topic/142882.rss" rel="self" type="application/rss+xml"/><pubDate>Thu, 13 Jan 2011 14:05:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Aiuto per sondaggio PHP on Thu, 13 Jan 2011 14:09:48 GMT]]></title><description><![CDATA[<p dir="auto">a scusate mi sono dimenticato il file della tabelle che cè nel database:</p>
<p dir="auto">install.php</p>
<pre><code class="language-php">&lt;?php

require("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!&lt;br /&gt;";
?&gt;
</code></pre>
]]></description><link>https://dev.connect.gt/post/964738</link><guid isPermaLink="true">https://dev.connect.gt/post/964738</guid><dc:creator><![CDATA[baxxter]]></dc:creator><pubDate>Thu, 13 Jan 2011 14:09:48 GMT</pubDate></item></channel></rss>