Hallo,
habe mir ein tolles voting-script auf Mysql-Basis downgeladen.
Die ersten Tage hat es auch wunderbar funktioniert.
Doch jetzt scheint ein Fehler in der Datenbank zu sein.
Ich kann keine neuen Umfragen mehr abspeichern:
Komischerweise funktioniert das Script auch auf anderen Server nicht,
habs versucht.
Habe mal einen Screenshot meiner Mysql-Admin angehängt:
Wer kann mir sagen, wo der Fehler liegt?
Hier der Code für die vote.php:
Und hier der Code für die admin.php:
Danke für die Hilfe,
Werner
habe mir ein tolles voting-script auf Mysql-Basis downgeladen.
Die ersten Tage hat es auch wunderbar funktioniert.
Doch jetzt scheint ein Fehler in der Datenbank zu sein.
Ich kann keine neuen Umfragen mehr abspeichern:
Komischerweise funktioniert das Script auch auf anderen Server nicht,
habs versucht.
Habe mal einen Screenshot meiner Mysql-Admin angehängt:
Wer kann mir sagen, wo der Fehler liegt?
Hier der Code für die vote.php:
PHP-Code:
<?
require_once("settings.inc");
$poll = mysql_connect("$db_host", "$db_username", "$db_password")
or die ("Could not connect");
mysql_select_db ("d001eeed")
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><br><br>";
$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).<br>";
echo "<img src=\"$imageid.gif\" width=\"$imagewidth\" height=\"10\" style=\"border:1px solid black\"><br><br>";
$imageid++;
}
echo "<br>A total of $totalvotes votes has been submitted on this question.</font>";
}
if (!$submit && !$results) {
?>
<form method="post" action="<?=$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[2];
$question = $question[1];
echo "<b>$question</b><br><br>";
$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 (!$checkedvar){ echo "checked"; $checkedvar=1; }
echo ">";
echo " ".$writeit["alternative"]."<br>";
}
echo "<input type=\"hidden\" name=\"pollid\" value=\"$pollid\"></font>";
echo "<br><center><input type=\"Submit\" value=\"Vote\" name=\"submit\"";
echo " style=\"background-color:white; color:black; font-family:Verdana; font-size:12px\"><br>";
echo "<font face=\"Verdana\" size=\"1\"><a href=\"".$PHP_SELF."?results=1\" target=\"_blank\">View results</a></font>";
echo "</center></form>";
}
elseif ($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.<br><br></font>";
}
else { echo "<font face=\"Verdana\" size=\"2\">Only one vote per ip allowed.<br><br></font>";}
// skriva ut resultat
writeresults();
}
elseif($results){
writeresults();
}
mysql_close($poll);
?>
PHP-Code:
<?
require_once("../settings.inc");
function insert($field,$pollid){
mysql_query ("insert into poll_alternatives (poll_id,alternative,votes) values ('$pollid','$field','0')");
echo "insert into poll_alternatives (poll_id,alternative,votes) values ('$pollid','$field','0')<br>";
}
if (!$submit){
?>
<font face="Verdana" size="2">
<form method="post" action="<?=$PHP_SELF ?>?submit=yes">
<b>Question:</b><br>
<input type="text" name="question"><br><br>
<b>Alternative 1:</b> <input type="text" name="alt"><br>
<b>Alternative 2:</b> <input type="text" name="alt2"><br>
<b>Alternative 3:</b> <input type="text" name="alt3"><br>
<b>Alternative 4:</b> <input type="text" name="alt4"><br>
<b>Alternative 5:</b> <input type="text" name="alt5"><br>
<b>Alternative 6:</b> <input type="text" name="alt6"><br>
<b>Alternative 7:</b> <input type="text" name="alt7"><br>
<b>Alternative 8:</b> <input type="text" name="alt8"><br><br>
<input type="submit" name="submit" value="Submit">
</FORM></font>
<?
}
else{
$poll = mysql_connect("$db_host", "$db_username", "$db_password")
or die ("Could not connect");
mysql_select_db ("d001eeed")
or die ("Could not select database");
$checkforpoll=mysql_query("select * from polls");
if (mysql_num_rows($checkforpoll)==0){
$date = date("Y-m-d");
mysql_query ("insert into polls (question, active,dateactive,votes) values ('$question','yes',$date,'0')");
echo "insert into polls (question, active,dateactive,votes) values ('$question','yes',$date,'0')<br><br>";
}
else {
mysql_query ("insert into polls (question, active,votes) values ('$question','no','0')");
echo "insert into polls (question, active,votes) values ('$question','no','0')<br><br>";
}
$getpollid = mysql_query("select id from polls where question='$question' order by id desc limit 1");
$getitid = mysql_fetch_row($getpollid);
$pollid = $getitid[0];
if($alt){ insert($alt,$pollid);}
if($alt2){ insert($alt2,$pollid); }
if($alt3){ insert($alt3,$pollid); }
if($alt4){ insert($alt4,$pollid); }
if($alt5){ insert($alt5,$pollid); }
if($alt6){ insert($alt6,$pollid); }
if($alt7){ insert($alt7,$pollid); }
if($alt8){ insert($alt8,$pollid); }
mysql_close($poll);
}
?>
Werner
Kommentar