Yes I'll do so. I just thought somebody could give me a better version of the piece of code because some guys commented on that.
I customized the layout a bit, but everything the cript needs is there. It also connects to the database. But the database doesn't look like it should (Image attached). I think this is also the reason why the script doens't count the vote.
Here is my edited code:
poll.php
<form method="post" action="poll_one.php">
<table align="center" border="0" width="148" bgcolor="#E6E6E6" cellpadding="3"
cellspacing="0">
<tr>
<td width="100%">
<table border="0" cellpadding="0">
<tr>
<td>
<BR>
<font face="Tahoma" color="000000">
<strong>Wie findet ihr das Design?</strong><BR><BR>
<input type="radio" name="rd" value="1">Super<br>
<input type="radio" name="rd" value="2">Ganz gut<br>
<input type="radio" name="rd" value="3">Mittelmäßig<br>
<input type="radio" name="rd" value="4">Ich kann es besser<br>
<input type="radio" name="rd" value="5">Grottig!<br>
</font>
</td>
</tr>
</table>
</td>
</tr>
<tr>
<td align="center">
<input type="submit" value="Vote!" name="Submit">
<small>
<a href="poll_one.php?target=currentresults"><br>Ergebniss</a>
</small>
</td>
</tr>
</table>
</form>
My poll_one.php
<html>
<head>
<title>Poll</title>
</head>
<body bgcolor="white" text="black">
<?php
//Damit die Deklaration am Anfang ordentlich ist
//host = "localhost"
//user = "mrnfk"
//pw = ""
//db = "mrnfk_de_db"
$conn = mysql_connect("localhost", "mrnfk", "");
mysql_select_db($db,$conn);
// This will get the users IP address and store it into the variable $ip.
$ip = getenv("REMOTE_ADDR");
// This will select the current information from the database.
// This allows us to compare it to the user's IP
// to assure validity of the votes coming in.
$bjork = "select ip from polls";
$sucks = mysql_query($bjork);
// Set this variable to no in order to indicate that the
// IP address hasn't been found in the database.
$asdf = no;
//This statement will put the value 'yes' into $asdf, if there is a
//matching IP address in the database. Therefore, the user will not
//be allowed to vote a second time.
while ($row=mysql_fetch_array($sucks)){
if ($ip==$row[0]){
$asdf = 'yes';
}
}
// If the IP is found, output the error message.
if ($asdf != 'no'){
echo "Du hast schon mal gevotet.<br>\n";
echo "Klick <a href=\"currentresults.php\">hier</a>
um das Ergebnis zu betrachten.<br>\n";
}
else {
// Otherwise, input the data and show the results.
$joke = "insert into polls VALUES('$rd','$ip')";
$er = mysql_query($joke);
// These select statements will select results for each possible answer.
$moan = "select rd from polls where rd like '1'";
$hard = mysql_query($moan);
$moantwo = "select rd from polls where rd like '2'";
$hardtwo = mysql_query($moantwo);
$moanthree = "select rd from polls where rd like '3'";
$hardthree = mysql_query($moanthree);
$moanfour = "select rd from polls where rd like '4'";
$hardfour = mysql_query($moanfour);
$moanfive = "select rd from polls where rd like '5'";
$hardfive = mysql_query($moanfive);
$moaning = "select rd from polls";
$harder = mysql_query($moaning);
// These variables are for getting the number of entries for each answer.
$one = mysql_num_rows($hard);
$two = mysql_num_rows($hardtwo);
$three = mysql_num_rows($hardthree);
$four = mysql_num_rows($hardfour);
$five = mysql_num_rows($hardfive);
$all = mysql_num_rows($harder);
//This will take the percentage of each entry and allow the
//user can see how each answer is doing.
$percentone = (100 / $all) * $one;
$percenttwo = (100 / $all) * $two;
$percentthree = (100 / $all) * $three;
$percentfour = (100 / $all) * $four;
$percentfive = (100 / $all) * $five;
// This will round the numbers to the nearest percentage point.
$percentone = round($percentone);
$percenttwo = round($percenttwo);
$percentthree = round($percentthree);
$percentfour = round($percentfour);
$percentfive = round($percentfive);
//This multiplies the percentages by four to create the width
//for the 1 pixel wide image to display in the bar graph.
$fakeone = ($percentone * 4);
$faketwo = ($percenttwo * 4);
$fakethree = ($percentthree * 4);
$fakefour = ($percentfour * 4);
$fakefive = ($percentfive * 4);
// And now, we show the graph.
echo "<center><br><br><br><br>\n";
echo "<table border=\"1\" width=\"40%\" bgcolor=\"#DDDDDD\"
cellpadding=\"3\" cellspacing=\"0\" bordercolor=\"#000000\">\n";
echo " <tr>\n";
echo " <td width=\"100%\" bgcolor=\"#C60029\" valign=\"middle\"
align=\"center\"><font face=\"Tahoma\" color=\"white\"
size=3><b>Poll Results</b></font></td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td width=\"100%\">\n";
echo " <table border=\"0\" cellpadding=\"0\">\n";
echo " <tr>\n";
// Here, we will show the entry subject and how many votes it received.
echo " <td>Super! ($one):</td>\n";
// This will show the bar with the actual percentage it represents after it.
echo " <td><img src=\"pixel.jpg\" width=\"$fakeone\" height=18>$percentone%</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td>Ganz gut ($two):</td>\n";
echo " <td><img src=\"pixel.jpg\" width=\"$faketwo\" height=18>$percenttwo%</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td>Mittelmäßig ($three):</td>\n";
echo " <td><img src=\"pixel.jpg\" width=\"$fakethree\" height=18>$percentthree%</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td>Ich kann es besser ($four):</td>\n";
echo " <td><img src=\"pixel.jpg\" width=\"$fakefour\" height=18>$percentfour%</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td>Grottig! ($five):</td>\n";
echo " <td><img src=\"pixel.jpg\" width=\"$fakefive\" height=18>$percentfive%</td>\n";
echo " </tr>\n";
echo " <tr>\n";
echo " <td colspan=2><center>Total Votes: $all</center></td>\n";
echo " </tr>\n";
echo " </table>\n";
echo " </td>\n";
echo " </tr>\n";
echo "</table>\n";
echo "</center>\n";
}
?>
</body>
</html>
Don't care that the voting Options are german 🙂