Results 1 to 3 of 3

Thread: PHP editing MySQL tables.

  1. #1
    Join Date
    Aug 2011
    Posts
    32
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default PHP editing MySQL tables.

    Okay, I have a "ingame store" on a game and it uses a database to store the prices and everything, and I also have an economy plugin, what I need to do is this:

    I want a form that will buy it rather than in game, but on a website.

    So here is what I mean: If someone wanted to buy an item, they could go to the website, find the item in a list, and when they click the link, that link contains variables, such as this:

    http://mywebsite.com/shop/buy.php?id=82


    But this will get a little tricky:

    It needs to CHECK the price from the database containing the item list, then it would need to ADD a random code to another database (it would echo it to them, while adding the item's ID, and it's quanity like so: 82 1 (it would give them item 82, and give them only 1 of this item). And THEN, I need it to subtract the amount of money (the amount in the item database, aka the buy price) and it needs to subtract it from their username (specified via a login system). I know thats gonna be hard, I'm really getting headaches trying to figure it out.

    Any help would be appriciated.

    (by the way, I didn't know if I should put this in PHP or MySQL)


    Hopefully you guys can help me

    EDIT: If needed, I can put the buy price as a variable like so: http://mywebsite.com/shop/buy.php?item=82&p=20 p means price.
    Last edited by Techykid3; 08-12-2011 at 08:56 PM.

  2. #2
    Join Date
    Mar 2007
    Location
    New York, NY
    Posts
    557
    Thanks
    8
    Thanked 66 Times in 66 Posts

    Default

    *scratches head*

    Are you referring to query strings when you say "variables"? Query strings are like the following: let's say you have ?id=82 at the end of http://mywebsite.com/shop/buy.php. The id becomes a variable with the value of 82. In PHP, you could read query string variables using the $_GET variable. For example, if you had the URL http://mywebsite.com/shop/buy.php?id=82:
    PHP Code:
    <?php

    echo $_GET['id'];

    ?>
    ...would print "82" on the webpage.

    How to find a product: Well, since you clearly want a MySQL solution, here's a stab at it.

    Let's say you have a table named `products` with product_id as the primary key. You could write somehting like:
    PHP Code:
    <?php

    // Connect to MySQL.

    $product_id mysql_escape_string($_GET['id']);

    $query mysql_query("SELECT * FROM `products` WHERE product_id = $product_id") or die(mysql_error());

    ?>
    And that would query the database.

    As for the rest, do you mean "add a random code to another database", do you mean another table? Because that's different. If you want to add it to another database, you're going to need to disconnect and then reconnect MySQL.

    Do you have any code for us to work with/
    - Josh

  3. #3
    Join Date
    Aug 2011
    Posts
    32
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    I mean't in a different table. I don't have any code so far. Thats why I'm here, I need it written, or somewhat "taught" to me.. I am in no rush to finish this project, but I really know its possible, i've seen it done before.

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
  •