A voting system not working, correctly.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

A voting system not working, correctly.

Post by impulse() »

The following code allows the values in my DB to reach 2 and then stop incrementing. There's 1 row in my DB which contains 'id', 'cplus', 'java' & 'php' and I start with them all containing a value of 0 besides the ID which I set as 1.

Code: Select all

<form method="post"
      action="vote.php">
<input type="radio" value="C++" name="proglan" /> C++<br>
<input type="radio" value="Java" name="proglan" /> Java<br>
<input type="radio" value="PHP" name="proglan" /> PHP<br>
<br>
<input type="submit"
       value="Vote">
</form>

<?php
include_once("/var/www/html/php/db/logon.php");

mysql_connect($host, $user, $pass);
mysql_select_db(poll);
$qu = "SELECT * FROM votes";
$results = mysql_query($qu);


$vote = $_REQUEST["proglan"];

if ($vote == "C++") {
  $cplus = mysql_result($results, "cplus");
  $newCplus = $cplus + 1;
  $q = mysql_query("UPDATE votes SET cplus='$newCplus'");
  echo "Added your vote to C++<br><br>";
}

else if ($vote == "Java") {
  $java = mysql_result($results, "java");
  $newJava = $java + 1;
  $q = mysql_query("UPDATE votes SET java='$newJava'");
  echo "Added your vote to Java<br><br>";
}

else if ($vote == "PHP") {
  $php = mysql_result($results, "php");
  $newPhp = $php + 1;
  $q = mysql_query("UPDATE votes SET php='$newPhp'");
  echo "Added your vote to PHP<br><br>";
}
Last edited by impulse() on Mon Sep 18, 2006 12:11 pm, edited 1 time in total.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

That is nice, so what is the problem?
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

It doesn't increment any of the columns once they hit '2' votes. If I reset all of the counters to 0 then on the first vote it increments from 0 to 2 and then goes no further.
impulse()
Forum Regular
Posts: 748
Joined: Wed Aug 09, 2006 8:36 am
Location: Staffordshire, UK
Contact:

Post by impulse() »

Ignore me I'm a daft sod. I wasn't specifing what row of the table to grab the results from.

All's working fine now.
Post Reply