PDA

View Full Version : MySql/PHP Voting System - Problem



Echo54321
06-07-2008, 04:10 PM
I have just been coding my Games site when i came across making the voting system

I made Vote.php:


<?php
$game = $_GET['game'];
$vote = $_GET['vote'];
$sql_query = "UPDATE `votes` SET `echo $vote;` = +1 WHERE `id` = '$game'";
if(mysql_query($sql_query)) {
echo "Voted";
}
?>

And i have a table called 'votes' with 6 fields 5,4,3,2,1,id

So each game has a row with ID as the game id and 5,4,3,2,1 as 0 untill someone votes

but when i go on..

vote.php?game=2&vote=3

Basically: GAME=2 Is the game ID
and vote=3 Is what you vote

but when i go on it, nothing happens, when it should put the vote '3' for game id '2' up one
what can i do?

Independent
06-07-2008, 04:24 PM
I have just been coding my Games site when i came across making the voting system

I made Vote.php:


<?php
$game = $_GET['game'];
$vote = $_GET['vote'];
$sql_query = "UPDATE `votes` SET `echo $vote;` = +1 WHERE `id` = '$game'";
if(mysql_query($sql_query)) {
echo "Voted";
}
?>And i have a table called 'votes' with 6 fields 5,4,3,2,1,id

So each game has a row with ID as the game id and 5,4,3,2,1 as 0 untill someone votes

but when i go on..

vote.php?game=2&vote=3

Basically: GAME=2 Is the game ID
and vote=3 Is what you vote

but when i go on it, nothing happens, when it should put the vote '3' for game id '2' up one
what can i do?
Try inserting the connection code.

Protege
06-07-2008, 04:25 PM
I have just been coding my Games site when i came across making the voting system

I made Vote.php:


<?php
$game = $_GET['game'];
$vote = $_GET['vote'];
$sql_query = "UPDATE `votes` SET `echo $vote;` = +1 WHERE `id` = '$game'";
if(mysql_query($sql_query)) {
echo "Voted";
}
?>And i have a table called 'votes' with 6 fields 5,4,3,2,1,id

So each game has a row with ID as the game id and 5,4,3,2,1 as 0 untill someone votes

but when i go on..

vote.php?game=2&vote=3

Basically: GAME=2 Is the game ID
and vote=3 Is what you vote

but when i go on it, nothing happens, when it should put the vote '3' for game id '2' up one
what can i do?

Basically cause you don't understand syntax of PHP...

<?php
if ( $_GET[ 'game' ] != '' )
{
$mysqlQuery = mysql_query ( 'UPDATE `votes` SET `vote` = `vote`+1 WHERE `id` = ' . mysql_real_escape_string ( $_GET[ 'game' ] ) . ' LIMIT 1 ;' );

if ( $mysqlQuery )
{
echo ( 'Voted' );
}
else
{
echo ( 'Failed' );
}
}
// Thats what I made from your coding, dont know why you need the $vote code if your just incrementing a field.
?>


Try inserting the connection code.

Then it would just error you

Echo54321
06-07-2008, 04:26 PM
No.., I need 5 different fields

So you can see how many ppl voted 5 how many 4, etc..

Independent
06-07-2008, 04:34 PM
If he never inserted the connection code it would do nothing anyway, because it would not update anything, as it cannot connect.

Protege
06-07-2008, 04:37 PM
it would go lalal cannot connect @ laalal @adla on line 1 etflala he says "nothings happening" basically, the MYSQL database isn't being updated.

Echo54321
06-07-2008, 04:39 PM
The Connection code is there i can assure you

It was the syntax

Decode
06-07-2008, 06:55 PM
<?php
$game = $_GET['game'];
$vote = $_GET['vote'];
$sql_query = "UPDATE `votes` SET `" . $vote . "` = +1 WHERE `id` = '" . $game . "'";
if( isset ( $vote ) && isset ( $game ) ) {
mysql_query($sql_query);
echo "Voted";
}
else {
echo "Failed to vote";
}
?>

Want to hide these adverts? Register an account for free!