回声没有结果


No results on echo

我编写这段php代码是为了从API获得结果,但它不起作用。我对变量做了一些回声检查,以检查它们是否显示在屏幕上,但仍然没有显示。有什么解决方案或想法吗?为什么?

谢谢。

 <?php
    $item = $_GET['item'];
    $item = str_replace("'"", "", $item);
    $item = str_replace("''", "", $item);
    $item = str_replace(" ", "%20", $item);
    $item = str_replace("''", "", $item);
    @include_once ("pdocon.php");
    $code='SELECT auth FROM auth where id=1';
    echo $code;
    $stmt = $dbh->prepare("SELECT * FROM items WHERE name=?");
    $stmt->execute(array($item));
    $rs = $stmt->fetch(PDO::FETCH_ASSOC);
    if(!empty($rs)) {
            if(time()-$rs["lastupdate"] < 604800) die($rs["cost"]);
    }
    $link = "https://bitskins.com/api/v1/get_item_price/?api_key=(an api key here)&code=".$code"&names=".$item;
    $string = file_get_contents($link);
    $json = $string;
    $obj = json_decode($json);
    echo $obj;
    //print $obj->{"median_price"}; // 12345
    //$obj = json_decode($string);
    if($obj->{'status'} == "success") die("notfound");
    $lowest_price = $obj->{'price'};
    $lowest_price=str_replace("$", "", $lowest_price);
    $lowest_price = (float)($lowest_price);
    //$stmt = $dbh->prepare("DELETE FROM items WHERE name=?");
    //$stmt->execute(array($item));
    $stmt = $dbh->prepare("UPDATE items SET `cost` = ?,`lastupdate` = ? WHERE `name` = ?");
    $stmt->execute(array($lowest_price, time(), $item));
    $stmt = $dbh->prepare("INSERT INTO items (`name`,`cost`,`lastupdate`) VALUES (?, ?, ?)");
    $stmt->execute(array($item, $lowest_price, time()));
    echo $lowest_price;
    ?>

更新:由于某些原因,结果没有导入数据库,所以我将尝试将所有内容分解为更小的部分:这是来自pdocon.php:的代码

<?php
$user="";
$pass="";
try {
    $dbh = new PDO('mysql:host=localhost;dbname=testjackpot', $user, $pass);
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
?>

这就是表auth的样子:https://gyazo.com/75ea3a77773820f0c3adbdc24fc99185

这是API调用的结果:https://gyazo.com/efe5680baad104be97281c5dac3d2c58

出于某种原因,即使进行print_r($code),也不会在这个php生成的网页上显示任何内容。

更新2:

尝试使用

<?php
$item = $_GET['item'];
$item = str_replace("'"", "", $item);
$item = str_replace("''", "", $item);
$item = str_replace(" ", "%20", $item);
$item = str_replace("''", "", $item);
@include_once ("set.php");
$code=mysql_query("SELECT auth FROM auth where id=1");
echo $code;
$rs = mysql_query("SELECT * FROM items WHERE name='$item'");
if(mysql_num_rows($rs) > 0) {
    $row = mysql_fetch_array($rs);
    if(time()-$row["lastupdate"] < 3600) die($row["cost"]);
}
$link = "https://bitskins.com/api/v1/get_item_price/?api_key=(code)&code=".$code."&names=".$item."&delimiter=!END!";
$string = file_get_contents($link);
echo $string;
$obj = json_decode($string);
if($obj->{'success'} == "0") die("notfound");
$lowest_price = $obj->data->prices[0]->price;
$lowest_price[strlen($lowest_price)] = 0;
$lowest_price = str_replace("$","",$lowest_price);
$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 $lowest_price;
?>

仍然没有表现出任何东西。更新3:对于上面的最后一个代码,我终于得到了一些东西:gyazo。com/9fde818695abac2f4fe7997482ba865

您的语法有错误-$code"&names 之间必须有一个点

$link = "https://bitskins.com/api/v1/get_item_price/?api_key=(an api key here)&code=".$code."&names=".$item;


要查看您所犯的错误,可以添加

php_flag display_errors on

到.htaccess文件(仅在网站的开发人员版本)

尝试不使用@before-include_one。可能路径错误或文件不可访问。