I need help with mysql

So I voted in the poll I made but the results haven’t changed, so…

The problem is either with the database, which does not receive the data I gave him;
or I just didn’t present the results correctly, so that the poll results are shown to the user as null (0) every time.

Here’s the code:

poll.php

[PHP]

<?php include("login.php"); echo "

POLL

"; echo ""; echo "

Which browser are you using?

"; echo " Internet Explorer
"; echo " Mozilla Firefox
"; echo " Google Chrome
"; echo ""; echo "see results"; echo ""; ?>

[/PHP]

results.php
[php]

<?php include("login.php"); function cookie_check() { if (isset($_COOKIE['username']) AND isset($_COOKIE['password'])) return true; elseif (!$_COOKIE['username']) return false; } if (!cookie_check()) echo "You must be logged in to vote in this poll!"; elseif (cookie_check() AND isset($_POST['submit_poll']) AND !isset($_COOKIE['voted'])) { if ($_POST['a']) $vote = 'a'; elseif ($_POST['b']) $vote = 'b'; elseif($_POST['c']) $vote = 'c'; $result = mysql_query ("SELECT `" . '$vote' . "` FROM poll_table"); $row = mysql_fetch_row($result); if ($row[0]) $row[0] = $row[0]++; else $row[0] = 1; mysql_query ("UPDATE poll_table SET" . $vote . "='{$arr[0]}' "); $user = $_COOKIE['username']; setcookie('voted', '$user', time()+3600); } echo "

POLL RESULTS

"; $queryt = mysql_query ("SELECT * FROM poll_table"); $arr = mysql_fetch_array($queryt); $all = $arr['a'] + $arr['b'] + $arr['c']; if ($all) { $a = $arr['a'] / $all; $b = $arr['b'] / $all; $c = $arr['c'] / $all; } else { $a = 0; $b = 0; $c = 0; } echo "Internet Explorer: " . $a . "%
"; echo "Mozilla Firefox: " . $b . "%
"; echo "Google Chrome: " . $c . "%
"; ?>

[/php]
Help me Tell me what’s wrong with my code… I am novice at this…

I think problem is in this line:
[php]mysql_query (“UPDATE poll_table SET” . $vote . "=’{$arr[0]}’ ");[/php]

You’re missing space between SET and field name. Try to change the line above to this:
[php]mysql_query (“UPDATE poll_table SET " . $vote . “=’”.$arr[0].”’");[/php]

Nope. The results still remain 0% for all.
Maybe the problem is with these lines:
[php]
$queryt = mysql_query (“SELECT * FROM poll_table”);
$arr = mysql_fetch_array($queryt);

$all = $arr[‘a’] + $arr[‘b’] + $arr[‘c’];
if ($all) {
$a = $arr[‘a’] / $all;
$b = $arr[‘b’] / $all;
$c = $arr[‘c’] / $all;
}
else {
$a = 0;
$b = 0;
$c = 0;
}
[/php]
Please help :frowning:

Sponsor our Newsletter | Privacy Policy | Terms of Service