Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2007
    Posts
    144
    Tokens
    0

    Default MySql/PHP Voting System - Problem

    I have just been coding my Games site when i came across making the voting system

    I made Vote.php:

    PHP Code:
    <?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?
    Last edited by Echo54321; 06-07-2008 at 04:11 PM.

  2. #2
    Join Date
    Dec 2007
    Posts
    1,683
    Tokens
    0

    Latest Awards:

    Default

    Quote Originally Posted by Echo54321 View Post
    I have just been coding my Games site when i came across making the voting system

    I made Vote.php:

    PHP Code:
    <?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.

  3. #3
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    Quote Originally Posted by Echo54321 View Post
    I have just been coding my Games site when i came across making the voting system

    I made Vote.php:

    PHP Code:
    <?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 Code:
    <?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.
    ?>
    Quote Originally Posted by Independent View Post
    Try inserting the connection code.
    Then it would just error you
    Hi, names James. I am a web developer.

  4. #4
    Join Date
    Nov 2007
    Posts
    144
    Tokens
    0

    Default

    No.., I need 5 different fields

    So you can see how many ppl voted 5 how many 4, etc..
    Last edited by Echo54321; 06-07-2008 at 04:27 PM.

  5. #5
    Join Date
    Dec 2007
    Posts
    1,683
    Tokens
    0

    Latest Awards:

    Default

    If he never inserted the connection code it would do nothing anyway, because it would not update anything, as it cannot connect.

  6. #6
    Join Date
    Mar 2008
    Location
    Swindon, UK
    Posts
    1,274
    Tokens
    187
    Habbo
    :Ltd

    Latest Awards:

    Default

    it would go lalal cannot connect @ laalal @adla on line 1 etflala he says "nothings happening" basically, the MYSQL database isn't being updated.
    Hi, names James. I am a web developer.

  7. #7
    Join Date
    Nov 2007
    Posts
    144
    Tokens
    0

    Default

    The Connection code is there i can assure you

    It was the syntax

  8. #8
    Join Date
    Dec 2006
    Posts
    3,970
    Tokens
    0

    Latest Awards:

    Default

    PHP Code:
    <?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";
        }
    ?>
    Last edited by Decode; 06-07-2008 at 06:56 PM.
    Lets set the stage on fire, and hollywood will be jealous.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •