douhuo1738 2013-04-10 19:13
浏览 38
已采纳

为什么这个PHP在执行时会使我的网站空白? [重复]

This question already has an answer here:

A website I'm making has two fields, and when you press the submit button runs the following PHP. If both fields are empty, however, the page returns blank, almost as if it runs exit() at a certain point.

else if ($_POST["submit"] == "Update Bookmark") {
$url_to_update = $_POST["url_to_update"];

if (strpos($url_to_update, "http") === false) {
$url_to_update = "http://" . $url_to_update;
}

// Check if this URL is already in Pinboard
$api_url = "https://*username*:*password*@api.pinboard.in/v1/posts/get?url=" . $url_to_update . "&format=json";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$json = curl_exec($ch);

curl_close($ch);

$values = json_decode($json);

// URL is already in Pinboard
  if (count($values["posts"]) > 0) {
$new_title = str_replace(" ", "%20", $_POST["new_title"]);
$api_url = "https://*username:password*@api.pinboard.in/v1/posts/add?url=" . $url_to_update . "&description=" . $new_title . "&format=json";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$json = curl_exec($ch);

curl_close($ch);

$values = json_decode($json);

  if ($values->result_code == "done") {
echo "<div class='success-message'><strong>Updated!</strong> Your bookmark has been successfully updated to the new title.</div>";
}
  else {
echo "<div class='error-message'><strong>Dang!</strong> Something messed up.</div>";
  }
}
// URL is not already in Pinboard, so add it for the user
  else {
$new_title = str_replace(" ", "%20", $_POST["new_title"]);
$api_url = "https://*username:password*@api.pinboard.in/v1/posts/add?url=" . $url_to_update . "&description=" . $new_title . "&format=json";

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, $api_url);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$json = curl_exec($ch);

curl_close($ch);

$values = json_decode($json);

if ($values->result_code == "done") {
echo "<div class='success-message'><strong>Added instead!</strong> There wasn't a bookmark with this URL already, so we added it.</div>";
  }
else if ($values->result_code == "missing url") {
echo "<div class='error-message'><strong>Invalid URL!</strong> That's not a valid URL!</div>";
  }
else {
echo "<div class='error-message'><strong>Dang!</strong> Something messed up.</div>";
    }
  }
}

Could anyone offer some help? I've scanned it over and over again, but I cannot find what's causing it.

</div>
  • 写回答

3条回答 默认 最新

  • dongtai419309 2013-04-10 19:18
    关注

    You probably turned off error reporting. Try putting this in your header:

    <?php
    ini_set('display_errors', 'On');
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分