SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Error in select

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

    Error in select

    Hi all,

    I am wondering if someone could tell me why I get this error but the record is still inserted and then if the browser is refreshed the error is not there anymore?

    Warning: Supplied argument is not a valid MySQL result resource in /home/starrpet/public_html/buyitem.php on line 76

    I'm going to give all the code cause I don't know where the error actually is.

    In my post Different if else question I had to add the uid variable to a select statement and that is when I started getting the error. (See notes in code)
    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))  // this is line 76 where it shows the error
    {        $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
      
    }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' AND uid={$session["uid"]}"//This is where I fixed my if else question and started getting the error.
    $result mysql_query($query);
    $row mysql_fetch_array($result);
    $iname $row[name];
    $ipid $row[image];
    $iitemid $row[id]; 
                    if (
    mysql_num_rows($result) == 0)
                    
    // 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);

    }

     }

    Thanks again for all your help
    Jennifer
    Wanna be php coder!

  2. #2
    Wibblesticks Gryff's Avatar
    Join Date
    Oct 2001
    Location
    Asgard
    Posts
    442
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    while(list($db)=mysql_fetch_row($ret))
    $user $db
    shouldnt that be
    PHP Code:
    while(list($db)=mysql_fetch_row($ret))
    {
    $user $db

  3. #3
    SitePoint Enthusiast gcarlyle's Avatar
    Join Date
    Mar 2002
    Location
    Olympia Wa
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually that wasn't the problem but I just changed line 76 to

    PHP Code:
    $row mysql_fetch_array($ret); 
    That cured the error and it works great.

    But thanks for trying.
    Jennifer
    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
  •