Hi all,

 I guess I should have gone ahead and put the whole code in because I didn't
get accomplished what I set out to do in the last if else question.

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?

$id = $HTTP_GET_VARS["id"];

$check_points = "SELECT points FROM {$config["prefix"]}_users WHERE

$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 StarrCredits to purchase this item!"; // If
there arent enough points to buy
    // 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"]}";
  // Updates the quantity
$query ="UPDATE {$config["prefix"]}_items SET quantity = quantity - 1 where
id = '$id'";

// We are selecting user id to insert into the users items.
$db="SELECT  uid FROM {$config["prefix"]}_users WHERE
$ret = mysql_query($db);
$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");

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



Any help is appreciated

Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.344 / Virus Database: 191 - Release Date: 4/2/2002

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to