2013-04-10 23 views
-2

我正在製作的網站有兩個字段,當您按下提交按鈕時,將運行以下PHP。但是,如果兩個字段都爲空,則頁面將返回空白,就好像它在某個點運行exit()一樣。爲什麼這個PHP在執行時讓我的網站變爲空白?

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>"; 
    } 
    } 
} 

任何人都可以提供一些幫助嗎?我一遍又一遍地掃描它,但我找不到是什麼原因造成的。

+4

如果你的腳本以'else if'開頭,這是一個非常好的指標,它會失敗。打開錯誤報告。 – Kermit 2013-04-10 19:17:26

+2

打開PHP錯誤和報告/日誌記錄! – 2013-04-10 19:17:28

+0

檢查你的錯誤日誌。可能是500錯誤。 – j08691 2013-04-10 19:17:31

回答

4

您可能關閉錯誤報告。嘗試把這個在你的頭:

<?php 
ini_set('display_errors', 'On'); 
?> 
1

如果放在php,那麼你應該用if首先啓動的ifelse報表情況下,唯一的代碼不直接與elseif嘗試使用第一個條件與if檢查

0

在你的PHP腳本的開頭將這個讓你可以得到一些適當的調試信息:

<?php 
    error_reporting(E_ALL); 
    ini_set('display_errors', TRUE); 
    ini_set('display_startup_errors', TRUE); 
    ini_set('memory_limit', '256M'); 
?> 

如果你還停留嘗試在這裏張貼的錯誤信息也許我們可以幫助你更多。

相關問題