PHP/MySQL Problem

Discussion in 'PHP' started by Blackmirth, Sep 10, 2007.

  1. #1
    Hello.
    I have tried to make a script that will update a user's 'points' if they post a correct answer.
    Unfortunately I can't get it to work. Could you help me out?


    <?php
    
            if (isset($_POST['answer'])){
                if ($_POST['answer'] == 'answer){
    
    $con = mysql_connect("XXXXXXXXXXXXXXX");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    mysql_select_db("b13_980789_db", $con);
    $username = $_SESSION['username'];
    $points = mysql_query("SELECT `points` FROM `b13_980789_db`.`users` WHERE `users`.`username` = '$username'");
    $pointsTwo = $points + 3;
    mysql_query("UPDATE `b13_980789_db`.`users` SET `points` = '$pointsTwo' WHERE `users`.`username` = '$username'");
    
    mysql_close($con);
    
                     echo "Congratulations.";}
            }
    ?>
    Code (markup):
     
    Blackmirth, Sep 10, 2007 IP
  2. abixalmon

    abixalmon Well-Known Member

    Messages:
    378
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Man!!!! are you gone crazy by giving out your mysql password in a Huge Forum like DP!
     
    abixalmon, Sep 10, 2007 IP
  3. Synchronium

    Synchronium Active Member

    Messages:
    463
    Likes Received:
    15
    Best Answers:
    0
    Trophy Points:
    58
    #3
    UPDATE `b13_980789_db` SET `points` = (`points` + 1);
     
    Synchronium, Sep 10, 2007 IP
  4. tamilsoft

    tamilsoft Banned

    Messages:
    1,155
    Likes Received:
    78
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Yes,
    Try to change your mysql password as soon as possible.

    For your problem, check the session variable, and you may shorten your query like this:

    "UPDATE `b13_980789_db`.`users` SET `points` = points+3 WHERE `users`.`username` = '$username'"
    Code (markup):
     
    tamilsoft, Sep 10, 2007 IP
  5. Blackmirth

    Blackmirth Peon

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thank you very much. I will try out the suggestions.

    I have also changed my password ^^.
     
    Blackmirth, Sep 10, 2007 IP