Rieccomi,
Ho questo script preso da freephp.it per rispondere ad un sondaggio.
Quello per inserire il sondaggio l'ho risolto grazie all'aiuto di Daniele.
Adesso non volevo rompere ulteriormente ma dopo svariati tentativi e letture di vari post sull'argomento sono riuscito ad evitere alcuni Notice ma alla fine mi da il seguente errore:
Notice: Undefined variable: PHP_SELF in C:\siti\prova\sonda\vote.php on line 71
questa è la linea 71
Codice PHP:
echo "<font face=\"Verdana\" size=\"1\"><a href=\"".$PHP_SELF."?results=1\" target=\"_blank\">View results</a></font>";
Questo è l'intero script
Codice PHP:
<?
require_once("settings.inc");
$poll = mysql_connect("$db_host", "$db_username", "$db_password")
or die ("Could not connect");
mysql_select_db ("cerebus")
or die ("Could not select database");
$checkforcurrent = mysql_query("select id,dateactive from polls where active='yes' order by question limit 1");
$current_poll = mysql_fetch_row($checkforcurrent);
$curpollid = $current_poll[0];
$dateactive = $current_poll[1];
$today=date("Y-m-d 00:00");
$date1=strtotime( "$dateactive 00:00" );
$date2=strtotime("$today");
$datediffer = (($date2-$date1)/86400);
if ($datediffer>=$interval){
$lookfornext = mysql_query("select id from polls where active='no' order by id limit 1");
$getnextid = mysql_fetch_row($lookfornext);
$nextpollid = $getnextid[0];
if ($nextpollid){
$date = date("Y-m-d");
mysql_query("update polls set active='end' where id=$curpollid");
mysql_query("update polls set active='yes', dateactive='$date' where id=$nextpollid");
mysql_query("delete from poll_ip");
}
}
function writeresults (){
$getquestion = mysql_query("select id,question,votes from polls where active='yes' order by question limit 1");
$question = mysql_fetch_row($getquestion);
echo "<font face=\"Verdana\" size=\"2\">[b]".$question[1]."[/b]
";
$totalvotes = $question[2];
$getresults = mysql_query("select votes, alternative from poll_alternatives where poll_id='$question[0]'");
$imageid=1;
while ($result = mysql_fetch_array($getresults)){
if ($totalvotes!=0){
$percentage = (round(($result["votes"]/$totalvotes)*10000))/100;
}
$imagewidth = round($percentage*2);
echo $result["alternative"]." - $percentage% (".$result["votes"]." votes).
";
echo "<img src=\"$imageid.gif\" width=\"$imagewidth\" height=\"10\" style=\"border:1px solid black\">
";
$imageid++;
}
echo "
A total of $totalvotes votes has been submitted on this question.</font>";
}
if(!isset($submit) & !isset($results)) {
?>
<form method="post" action="<? echo $_SERVER['PHP_SELF'] ?>" target="_blank">
<font face="Verdana" size="2">
<?
$getquestion = mysql_query("select id,question from polls where active='yes' order by question limit 1");
$question = mysql_fetch_row($getquestion);
$pollid = $question[0];
$dateactive = $question[1];
$question = $question[1];
echo "[b]$question[/b]
";
$getalternatives = mysql_query("select id, alternative from poll_alternatives where poll_id='$pollid'");
while ($writeit = mysql_fetch_array($getalternatives)){
echo "<input type=\"radio\" name=polloption value=\"".$writeit["id"]."\"";
if (!isset($checkedvar)){ echo "checked"; $checkedvar=1; }
echo ">";
echo " ".$writeit["alternative"]."
";
}
echo "<input type=\"hidden\" name=\"pollid\" value=\"$pollid\"></font>";
echo "
<center><input type=\"Submit\" value=\"Vote\" name=\"submit\"";
echo " style=\"background-color:white; color:black; font-family:Verdana; font-size:12px\">
";
echo "<font face=\"Verdana\" size=\"1\"><a href=\"".$PHP_SELF."?results=1\" target=\"_blank\">View results</a></font>";
echo "</center></form>";
}
elseif (isset($submit)){
$checkforip = mysql_query("select ip from poll_ip where ip='$REMOTE_ADDR'");
if (mysql_num_rows($checkforip)==0){
mysql_query ("update poll_alternatives set votes=votes+1 where id='$polloption'");
mysql_query ("update polls set votes=votes+1 where id='$pollid'");
mysql_query ("insert into poll_ip (ip) values ('$REMOTE_ADDR')");
echo "<font face=\"Verdana\" size=\"2\">Your vote has been counted.
</font>";
}
else { echo "<font face=\"Verdana\" size=\"2\">Only one vote per ip allowed.
</font>";}
// skriva ut resultat
writeresults();
}
elseif($results){
writeresults();
}
mysql_close($poll);
?>