0

I'm trying to get some prices straight from Steam API,

 $item = $_GET['item'];
 $item = str_replace("\"", "", $item);
 $item = str_replace("\'", "", $item);
 $item = str_replace(" ", "%20", $item);
 $item = str_replace("\\", "", $item);
 @include_once ("set.php");
 $rs = mysql_query("SELECT * FROM items WHERE name='$item'");
 if(mysql_num_rows($rs) > 0) {
 $row = mysql_fetch_array($rs);
 if(time()-$row["lastupdate"] < 604800) die($row["cost"]);
 }
 $link = "http://steamcommunity.com/market/priceoverview/?currency=1&appid=730&market_hash_name=".$item;
 $string = file_get_contents($link);
 $obj = json_decode($string, true);
 if($obj['success'] == "0") die("notfound");
 $lowest_price = $obj['lowest_price'];
 echo $obj->['lowest_price'];
 for($i = 5; $i < strlen($lowest_price); $i++) {
    $lowest_price[$i-5] = $lowest_price[$i];
 }
 $lowest_price[strlen($lowest_price)] = 0;
 $lowest_price = (float)($lowest_price);
 mysql_query("DELETE FROM items WHERE name='$item'");
 mysql_query("INSERT INTO items (`name`,`cost`,`lastupdate`) VALUES ('$item','$lowest_price','".time()."')");
 echo $link;
 echo $lowest_price;
 echo ' test ';
 ?>

However, I get the following error message:

Parse error: syntax error, unexpected '[', expecting identifier (T_STRING) or variable (T_VARIABLE) or '{' or '$' in /foo.php on line 19`

Can anyone help?

Matt
  • 74,352
  • 26
  • 153
  • 180
  • If you can, you should [stop using `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared](http://en.wikipedia.org/wiki/Prepared_statement) [statements](http://php.net/manual/en/pdo.prepared-statements.php) instead, and consider using PDO, [it's really not hard](http://jayblanchard.net/demystifying_php_pdo.html). – Jay Blanchard Sep 02 '15 at 16:58
  • Ok, But what I have now, Is the way to go? – TRITIX Production Sep 02 '15 at 16:59
  • In future, when you get a blank screen, add error reporting to the top of your file(s) right after your opening PHP tag for example ` – Funk Forty Niner Sep 02 '15 at 17:02
  • Plus, `'".time()."'` that's a function, *n'est-ce pas?* Why are you treating it as a string literal? – Funk Forty Niner Sep 02 '15 at 17:04

1 Answers1

3
echo $obj->['lowest_price'];

Should be

echo $obj->lowest_price; // This is how you access object properties

Since you mixed up array access format with property access format, there was a syntax error which caused you not to see any output.

Hanky Panky
  • 46,730
  • 8
  • 72
  • 95