Page 1 of 1

A voting system not working, correctly.

Posted: Mon Sep 18, 2006 10:54 am
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>";
}

Posted: Mon Sep 18, 2006 11:00 am
by JayBird
That is nice, so what is the problem?

Posted: Mon Sep 18, 2006 12:14 pm
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.

Posted: Mon Sep 18, 2006 12:44 pm
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.