-2

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.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
user212541
  • 1,878
  • 1
  • 21
  • 30

3 Answers3

4

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

<?php
ini_set('display_errors', 'On');
?>
George
  • 367
  • 1
  • 10
1

if this the only code placed in the php then you should start case of if else statements first with if not directly with elseif try using first condition with if check

M Khalid Junaid
  • 63,861
  • 10
  • 90
  • 118
0

Put this at the beginning of your PHP script so you can get some proper debug information:

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

If you are still stuck try posting the error message here and perhaps we can help you some more.

caponica
  • 3,788
  • 4
  • 32
  • 48