SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Australia
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php mySQL question.

    How to get php to add/subtract a number (in the php code not an input) from a mySQL table by the press of a button?

    e.g.

    Clicking a button (Sell) and it adds 50 to 9999.
    Clicking a button (Buy) and it subtracts 50 from 10049.

    That would be very useful in what I am building

    Thanks in advance.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2002
    Location
    Cincinnati, Ohio
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We need more information. Do you want a query? If you do try something like:
    UPDATE table SET total = total + 50

    More information on what you're trying to complete would be helpful. Also this isn't a very advanced topic so it probably should be moved.

  3. #3
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Australia
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm sorry... I thought of it as advanced.
    Well... I want a php script to send total (9999) + 50 (All in a mySQL db e.g. SELECT Cash FROM `users` where username = '$username' )
    and... well I'm not really a php person lolz so I think it would be a querry.

    hope that cleared it up for ya

    p.s. I already got a file that contains the mySQL login data. Its called database.php and it will be in the same directory as this file.

  4. #4
    SitePoint Member
    Join Date
    Dec 2004
    Location
    Australia
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    any one able to help me?

  5. #5
    SitePoint Wizard Lats's Avatar
    Join Date
    Jun 2003
    Location
    Melbourne, AU
    Posts
    1,142
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Maybe something like this...
    PHP Code:
    <?php
    include("database.php");
    $username $_POST['username'];
    $a = isset($_POST['a']) ? $a $_POST['a'] : $a $_GET['a'];
    if(
    $_POST['buy']) $value = -50;
    if(
    $_POST['sell']) $value 50;

    $sql "
        UPDATE
            users
        SET
            total = total + 
    $value
        WHERE
            username = '
    $username'
        "
    ;
    $result mysql_query($sql) or die(mysql_error());
    ?>
    Lats...


Bookmarks

Posting Permissions

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