Need Urgent Help!

Discussion in 'PHP' started by NateJ, May 27, 2009.

  1. #1
    Okay, So Everything works except the Variables called $item and $price For some unknown reason they don't get inserted.

    Here is the piece of coding that i'm using to do the job, anyone have any suggestions that will fix the problem?

    if ($user_shit->last_trade <= time()){
    $rand = rand(0,105);
    if ($rand <= 10){ $item == "Hidden Agenda"; 
    }elseif ($rand > 10 && $rand < 25){ $item =="Gang Informer";
    }elseif ($rand > 25 && $rand < 50){ $item =="Fake Evidence";
    }elseif ($rand > 50 && $rand < 100){ $item =="Super Cold Beer";
    }elseif ($rand > 100 && $rand <= 105){ $item =="Personal Spy";
    if($item == "Hidden Agenda"){ $price == "500000000";
    }elseif($item == "Personal Spy"){ $price == "1000000000"; 
    }else{ $price == rand(1000,250000000); }
    $timeleft = time() + (3600 * 24 * 2);
    mysql_query("INSERT INTO `items` ( `id` , `item` , `owner` , `detail`) 
    VALUES (
    '', '$item', 'The Global Thug', '1'
    )");
    $select = mysql_fetch_object(mysql_query("SELECT * FROM items WHERE item='$item' AND owner='The Global Thug'"));
    mysql_query("INSERT INTO `nate_global`.`trade_center` (`id`, `item`, `seller`, `price`, `time_left`, `item_id`, `anonymous`, `type`) VALUES ('', '$item', 'The Global Thug', '$price', '$timeleft', '$select->id', '0', 'item')");
    $last_time = time() + (3600 * 12);
    mysql_query("UPDATE site_stats SET last_trade='$last_time'");
    }}
    PHP:
    Thanks.
     
    NateJ, May 27, 2009 IP
  2. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try not mixing $price as a string and an integer - leave it as a float. and don't use == for assignments, it's for comparison only. so:

    if ($user_shit->last_trade <= time()){
    $rand = rand(0,105);
    if ($rand <= 10){ $item = "Hidden Agenda"; 
    }elseif ($rand > 10 && $rand < 25){ $item = "Gang Informer";
    }elseif ($rand > 25 && $rand < 50){ $item = "Fake Evidence";
    }elseif ($rand > 50 && $rand < 100){ $item = "Super Cold Beer";
    }elseif ($rand > 100 && $rand <= 105){ $item = "Personal Spy";
    if($item == "Hidden Agenda"){ $price = 500000000;
    }elseif($item == "Personal Spy"){ $price = 1000000000; 
    }else{ $price = rand(1000,250000000); }
    $timeleft = time() + (3600 * 24 * 2);
    mysql_query("INSERT INTO `items` ( `id` , `item` , `owner` , `detail`) 
    VALUES (
    '', '$item', 'The Global Thug', '1'
    )");
    $select = mysql_fetch_object(mysql_query("SELECT * FROM items WHERE item='$item' AND owner='The Global Thug'"));
    mysql_query("INSERT INTO `nate_global`.`trade_center` (`id`, `item`, `seller`, `price`, `time_left`, `item_id`, `anonymous`, `type`) VALUES ('', '$item', 'The Global Thug', '$price', '$timeleft', '$select->id', '0', 'item')");
    $last_time = time() + (3600 * 12);
    mysql_query("UPDATE site_stats SET last_trade='$last_time'");
    }}
    PHP:
     
    szalinski, May 27, 2009 IP