Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Updating info in database

    I have tried to make it update the info if it already exists but with no luck, I am a newbie to php and I hope you guys will help me
    PHP Code:
     <?php
    define
    ("DB_SERVER""xxxx");

    define("DB_USER""xxxx");

    define("DB_PASS""xxxx");

    define("DB_NAME""xxxx");

    mysql_connect(DB_SERVERDB_USERDB_PASS);
    mysql_select_db(DB_NAME);
    session_start();

    $runtime $_GET['runtime'];
    $user $_GET['username'];
    $profit $_GET['profit'];
    $exp $_GET['exp'];

    $query "SELECT * FROM rune_sig WHERE username = '$username'";
    $result mysql_query($query);

    if (
    mysql_num_rows($result) )
    {
    @
    mysql_query("UPDATE rune_sig SET runtime = '$runtime', exp = '$exp', profit = '$profit'");
    }
    else
    {
    if (
    $run>=&& $user && $profit>=&& $exp>=0) {
    @
    mysql_query("INSERT INTO rune_sig
    (`username`, `runtime`, `profit`, `exp`, `time`) VALUES 
    ('$user', '$runtime', '$profit', '$exp', NOW())"
    );
    } else {
    echo 
    '<font style="font-size:100px;font-family:georgia;"><br><center>GTFO</center></font>';
    echo 
    '<font style="font-size:50px;font-family:georgia;"><center><i>These are my PHP files.</i></center></font>';
    }
    }
    ?>
    Last edited by arturxxx; 10-27-2012 at 03:07 PM. Reason: Misspelled title

  • #2
    New Coder
    Join Date
    Sep 2011
    Posts
    74
    Thanks
    0
    Thanked 7 Times in 7 Posts
    Hi

    You need to tell MYSQL what row it needs to update. SO adding WHERE username = '$username' onto the end of the update query should do it.

  • #3
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by davidjones1990 View Post
    Hi

    You need to tell MYSQL what row it needs to update. SO adding WHERE username = '$username' onto the end of the update query should do it.
    Hmm, I didn't know that it would clear out the data and set it to the new one. Is there any way to add the value to the current one?

  • #4
    New Coder
    Join Date
    Sep 2011
    Posts
    74
    Thanks
    0
    Thanked 7 Times in 7 Posts
    So assuming that its a integer you can do something like this:

    profit = profit + '$profit'

    but depending on your need you may want to use CSV's so the info would look like this 10,20,30 or a seperate table altogether.

    If you explain what you are trying to do in more detail I could suggest some more detailed solutions.

  • #5
    New to the CF scene
    Join Date
    Oct 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Quote Originally Posted by davidjones1990 View Post
    So assuming that its a integer you can do something like this:

    profit = profit + '$profit'

    but depending on your need you may want to use CSV's so the info would look like this 10,20,30 or a seperate table altogether.

    If you explain what you are trying to do in more detail I could suggest some more detailed solutions.
    I got it to work, you can't imagine how happy I am right now. Thank you!

  • #6
    New Coder
    Join Date
    Sep 2011
    Posts
    74
    Thanks
    0
    Thanked 7 Times in 7 Posts
    No problem buddy


  •  

    Posting Permissions

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