0

I need to retrieve URL's which are coming from a PHP file which include mysql variables. Unfortunately they are not being returned correctly.

Below is the html file I am linking to:

<!doctype html>
<html>
<head>
  <meta charset="utf-8">
  <link rel="index" href="toc1.php" type="application/json">
</head>

My toc1.php was file:

<?php
  $username = $_GET['username'];
  $papername = $_GET['papername'];

  header('Content-Type: application/json');
  $username = json_encode($username);
  $papername = json_encode($papername);
?>

[{
"url": <?php echo '<a href="http://www.yoozpaper.com/cover.php?
username=' . $username . '&papername=' . $papername . '" ></a>';?>
},
{
"url": <?php echo '<a href="http://www.yoozpaper.com/tocindex.php?
username=' . $username . '&papername=' . $papername . '" ></a>';?>
},]

4 Answers 4

1

What about just removing the json_encode??

The json_encode function makes json object form array:

$json = array();
$json['something'] = "something else";
$json['and_again'] = "more things";

And then json_encode($json) returns:

{
     "something": "something",
     "and_again": "things"
}

So json encode a string:

$username = "John Doe";
echo json_encode($username);

Will result in something as "John Doe" or an error

0

I recommend following:

$list = array();

$objItem = new stdClass();
$objItem->url = '<a href="…?username=' . $username . '&papername=' . $papername . '"></a>';
$list[] = $objItem;

// add more items

And finally, output that:

echo json_encode($list);
0

The header() call must be the very first line of the file, see manual. So change it to

<?php
header('Content-Type: application/json');

$username = $_GET['username'];
$papername = $_GET['papername'];

$username = json_encode($username);
$papername = json_encode($papername);
?>

And from where the GET variables are supposed to come? You probably want to change the link to

<link rel="index" href="toc1.php?username=foo&papername=bar" type="application/json">
0

Your Json {"some":"some"}

here href=''

<a href='{"some":"some"}'>Some</a>

not this

<a href="{"some":"some"}">Some</a>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.