Awesomexr
New Member
- Messages
- 118
- Reaction score
- 4
- Points
- 0
What I'm working on: http://haslam.pcriot.com/games/4wheelmadness/4wheelmadness.php
Problem: Whenever i vote, down or up, a message is displayed "Thank you for your vote" but this message is displayed TWICE. And i have absoulutely no idea on how to make it only display once!
Here is the vote.php code:
I have underlined and bolded the echo that sends it. Any ideas why this is sending twice?
Don't worry, fixed now. Ajax side not php-side apparently.
Problem: Whenever i vote, down or up, a message is displayed "Thank you for your vote" but this message is displayed TWICE. And i have absoulutely no idea on how to make it only display once!
Here is the vote.php code:
Code:
<?php
include("config.php");
function getAllVotes($id)
{
/**
Returns an array whose first element is votes_up and the second one is votes_down
**/
$votes = array();
$q = "SELECT * FROM 4wheelmadness WHERE id = $id";
$r = mysql_query($q);
if(mysql_num_rows($r)==1)//id found in the table
{
$row = mysql_fetch_assoc($r);
$votes[0] = $row['votes_up'];
$votes[1] = $row['votes_down'];
}
return $votes;
}
function getEffectiveVotes($id)
{
/**
Returns an integer
**/
$votes = getAllVotes($id);
$effectiveVote = $votes[0];
return $effectiveVote;
}
function getEffectiveVotes2($id)
{
/**
Returns an integer
**/
$votes = getAllVotes($id);
$effectiveVote = $votes[1];
return $effectiveVote;
}
$id = $_POST['id'];
$action = $_POST['action'];
//get the current votes
$cur_votes = getAllVotes($id);
//ok, now update the votes
if($action=='vote_up') //voting up
{
$votes_up = $cur_votes[0]+1;
$q = "UPDATE 4wheelmadness SET votes_up = $votes_up WHERE id = $id";
}
elseif($action=='vote_down') //voting down
{
$votes_down = $cur_votes[1]+1;
$q = "UPDATE 4wheelmadness SET votes_down = $votes_down WHERE id = $id";
}
$r = mysql_query($q);
if($r) //voting done
{
// $effectiveVote = getEffectiveVotes($id);
// $effectiveVote2 = getEffectiveVotes2($id);
[U][B] echo "Thank you for your vote.";[/B][/U]
}
elseif(!$r) //voting failed
{
echo "There was an error processing your vote.";
}
?>
I have underlined and bolded the echo that sends it. Any ideas why this is sending twice?
Don't worry, fixed now. Ajax side not php-side apparently.
Last edited: