[PHP]
<?
require("config.php");
$sqldb = "outpost_general";
$conn = mysql_connect("$sqlhost","$sqluser","$sqlpass");
$sdb = mysql_select_db("$sqldb");
$query = "SELECT * FROM site_polls ORDER BY poll_id DESC LIMIT 1";
$result = mysql_query($query); $array = mysql_fetch_array($result);
$poll_id = $array[poll_id];
$query = "SELECT * FROM site_polls WHERE poll_id='$poll_id'";
$result = mysql_query($query); $array = mysql_fetch_array($result);
$poll_id = $array[poll_id];
$poll_name = $array[poll_name];
$poll_question = $array[poll_question];
$poll_option1 = $array[poll_option1];
$poll_option2 = $array[poll_option2];
$poll_option3 = $array[poll_option3];
$poll_option4 = $array[poll_option4];
$poll_option5 = $array[poll_option5];
$option1_text = $array[poll_option1txt];
$option2_text = $array[poll_option2txt];
$option3_text = $array[poll_option3txt];
$option4_text = $array[poll_option4txt];
$option5_text = $array[poll_option5txt];
$poll_votes = $array[poll_votes];
if(session_is_registered(poll)){
print "<center>$poll_name</center>";
print "<center>$poll_question</center>";
if($poll_option1 != 0) {
$Poll_Percent1 = Round(($poll_option1 / $poll_votes) * 100) . "%";
} else {
$Poll_Percent1 = 0 ."%";
}
if($poll_option2 != 0) {
$Poll_Percent2 = Round(($poll_option2 / $poll_votes) * 100) . "%";
} else {
$Poll_Percent2 = 0 ."%";
}
if($poll_option3 != 0) {
$Poll_Percent3 = Round(($poll_option3 / $poll_votes) * 100) . "%";
} else {
$Poll_Percent3 = 0 ."%";
}
if($poll_option4 != 0) {
$Poll_Percent4 = Round(($poll_option4 / $poll_votes) * 100) . "%";
} else {
$Poll_Percent4 = 0 ."%";
}
if($poll_option5 != 0) {
$Poll_Percent5 = Round(($poll_option5 / $poll_votes) * 100) . "%";
} else {
$Poll_Percent5 = 0 ."%";
}
if($option1_text != ""){
print "<IMG src=\"images/poll_bar.gif\" width=\"$poll_percent1\"><br>$option1_text :: $poll_option1 Votes<br>\n";
}
if($option2_text != ""){
print "<IMG src=\"images/poll_bar.gif\" width=\"$poll_percent2\"><br>$option2_text :: $poll_option1 Votes<br>\n";
}
if($option3_text != ""){
print "<IMG src=\"images/poll_bar.gif\" width=\"$poll_percent3\"><br>$option3_text :: $poll_option1 Votes<br>\n";
}
if($option4_text != ""){
print "<IMG src=\"images/poll_bar.gif\" width=\"$poll_percent4\"><br>$option4_text :: $poll_option1 Votes<br>\n";
}
if($option5_text != ""){
print "<IMG src=\"images/poll_bar.gif\" width=\"$poll_percent5\"><br>$option5_text :: $poll_option1 Votes<br>\n";
}
print "<center><a href=\"polls.php\" class=\"other_link\">Other Polls</a></center>";
}
else {
print "<center>$poll_name</center>";
print "<center>$poll_question</center>";
print "<form action=\"poll.php?mode=vote&id=$poll_id\" method=\"POST\">";
if($option1_text != ""){
print "<input type=\"radio\" name=\"vote\" value=\"option1\">$option1_text<br>";
}
if($option2_text != ""){
print "<input type=\"radio\" name=\"vote\" value=\"option2\">$option2_text<br>";
}
if($option3_text != ""){
print "<input type=\"radio\" name=\"vote\" value=\"option3\">$option3_text<br>";
}
if($option4_text != ""){
print "<input type=\"radio\" name=\"vote\" value=\"option4\">$option4_text<br>";
}
if($option5_text != ""){
print "<input type=\"radio\" name=\"vote\" value=\"option5\">$option5_text<br>";
}
print "<input type=\"submit\" value=\"value\">";
print "</form>";
}
?>
[/PHP]
Thats the code that shows the vote form, or if a session has been registered, show the results. Quite nice code bit. One problem though, The votes that are entered are in the mySQL database. But it doesnt show it, It always shows 0 votes, when i knowed i entered a vote. cause i checked in phpmyadmin. Any ideas people?
Can fat people Go skinny Dipping?
Comments
I've had a look at your code but it's difficult to debug without being able to simulate the execution. Could you tell me:
1. After you voted, check in phpmyadmin - did the data go in correctly?
2. If the data went into the database, did query 1 - "SELECT * FROM site_polls ORDER BY poll_id DESC LIMIT 1" return any results?
3. If so, did query 2 "SELECT * FROM site_polls WHERE poll_id='$poll_id'" return any results
4. If so, did the execution pass through your "if(session_is_registered(poll))" condition?
You can find out by simply putting some print statements after each of the critical points. If you could find out the above, someone can help you analyze the situation...
And when i go to print the variables, It only shows 0%, which means the variables weren't assigned, even thought it's perfect..
$poll_id = $array["poll_id"];
$poll_name = $array["poll_name"];
That should fix it
Works, That means the variable was assigned...
E.g. You did:
$poll_id = $array[poll_id];
instead of
$poll_id = $array["poll_id"];
1. data going into the database or
2. data coming out of the database for display
it'd be much easier to debug...