我正在制作的网站有两个字段,当您按下提交按钮时会运行以下PHP。但是,如果两个字段都为空,则页面返回空白,几乎就像它在某个点运行exit()
一样。
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>";
}
}
}
有人可以提供一些帮助吗?我一遍又一遍地扫描它,但我找不到导致它的原因。
答案 0 :(得分:4)
您可能已关闭错误报告。试着把它放在你的标题中:
<?php
ini_set('display_errors', 'On');
?>
答案 1 :(得分:1)
如果这是php
中唯一的代码,那么您应首先使用if
开始else
if
语句,而不是直接使用elseif
尝试使用if
检查的第一个条件
答案 2 :(得分:0)
将它放在PHP脚本的开头,以便获得一些正确的调试信息:
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
ini_set('memory_limit', '256M');
?>
如果您仍然卡住,请尝试在此处发布错误消息,也许我们可以为您提供更多帮助。