SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast gcarlyle's Avatar
    Join Date
    Mar 2002
    Location
    Olympia Wa
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Different if else question

    Hi all,

    I found a slight bug and am wondering if someone could help.

    If another user logs in and buys the same item as I do then my item is updated instead of adding the second user to the db and viseversa if they buy a different item.

    I have tried elseif with the uid but I am getting no where fast does anyone have any ideas?

    PHP Code:
    $id $HTTP_GET_VARS["id"];


    $check_points "SELECT points FROM {$config["prefix"]}_users WHERE uid={$session["uid"]}";
    $ret=mysql_query($check_points);

    while(list(
    $points)=mysql_fetch_row($ret))
    {
    $cost=$HTTP_SESSION_VARS['price'];  // Gets the price of the item. replace with $_SESSION['price'] if PHP version >= 4.1.0
                //echo $cost;
      
    if($points $cost) {
        echo 
    "You don't have enough SC to purchase this item!"// If there arent enough points to buy
      
    }
    else
    {
        
    // If there are enough points to buy then subtract the price from the users points
        
    $query "UPDATE {$config["prefix"]}_users SET points = points - $cost where uid={$session["uid"]}";
        
    mysql_query($query);
      
    // Updates the quantity
    $query ="UPDATE {$config["prefix"]}_items SET quantity = quantity - 1 where id = '$id'";
    $ret=mysql_query($query);

    // We are selecting user id to insert into the users items.
    $db="SELECT  uid FROM {$config["prefix"]}_users WHERE uid={$session["uid"]}";
    $ret mysql_query($db);
    while(list(
    $db)=mysql_fetch_row($ret))
    $user $db;

    // We are selecting everything from item where the id match the clicked item for insert into users items
    $query "SELECT * FROM {$config["prefix"]}_items where id = '$id'";
    $result mysql_query($query);
    $row mysql_fetch_array($result);
    $name $row[name];
    $pid $row[image];
    $itemid $row[id];

    // We are checking to see if the item exists in the user items
    $query "SELECT * FROM {$config["prefix"]}_my_items where id = '$id'";
    $result mysql_query($query);
    $row mysql_fetch_array($result);
    $iname $row[name];
    $ipid $row[image];
    $iitemid $row[id];
        if (
    mysql_num_rows($result) == 0)
    //This is where I think the problem is but I can't seem to figure  it out.
        // If the item doesn't then insert it into the users items
    {
    $query "INSERT INTO {$config["prefix"]}_my_items (uid, id, name, image) VALUES ('$user', '$itemid', '$name','$pid')";
    $ret mysql_query($query)
                     or die(
    "Unable to insert into the database");

        }else{
    // If it does exist the just update the quantity
    $query_update ="UPDATE {$config["prefix"]}_my_items SET quantity = quantity + 1 WHERE id = '$id'";
    $result=mysql_query($query_update);

    }

     }

    Any help is appreciated
    TIA
    Jennifer
    Wanna be php coder!

  2. #2
    We like music. weirdbeardmt's Avatar
    Join Date
    May 2001
    Location
    Channel Islands Girth: Footlong
    Posts
    5,882
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think your problem is this:

    PHP Code:
    $user $db
    I am sure that can't be right?

    Alternatively if that is right then this:

    PHP Code:
    $query "INSERT INTO {$config["prefix"]}_my_items (uid, id, name, image) VALUES ('$user', '$itemid', '$name','$pid')"
    surely isn't?
    I swear to drunk I'm not God.
    Matt's debating is not a crime
    Hint: Don't buy a stupid dwarf Clicky

  3. #3
    SitePoint Enthusiast gcarlyle's Avatar
    Join Date
    Mar 2002
    Location
    Olympia Wa
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is correct it works fine for one user.

    But if another loggs in and buys the same item only my item is updated. The other user is not added to the db with that item.
    Wanna be php coder!


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
  •