0

Hi I am trying to create my first REST service and have spent some time reading tutorials, I am following one through and in the client code I am getting a "=" in a unquoted attribute value. in the href line between the last <li> entry. I can't see whats wrong. I would like to get the example working and then build it up for the solution I am working on.

<?php

/*** this is the client ***/

if (isset($_GET["action"]) && isset($_GET["id"]) && $_GET["action"] == "get_user") // if the   get parameter action is get_user and if the id is set, call the api to get the user information
{
 $user_info = file_get_contents('http://localhost/RestServer/api.php?action=get_user&id=' . $_GET ["id"]);
$user_info = json_decode($user_info, true);

// THAT IS VERY QUICK AND DIRTY !!!!!
?>
<table>
  <tr>
    <td>Name: </td><td> <?php echo $user_info["last_name"] ?></td>
  </tr>
  <tr>
    <td>First Name: </td><td> <?php echo $user_info["first_name"] ?></td>
  </tr>
  <tr>
    <td>Age: </td><td> <?php echo $user_info["age"] ?></td>
  </tr>
</table>
<a href="http://localhost/RestClient/index.php?action=get_userlist" >Return to the user list</a>
<?php
}
else // else take the user list
{
$user_list = file_get_contents('http://localhost/RestServer/api.php?action=get_user_list');
$user_list = json_decode($user_list, true);
// THAT IS VERY QUICK AND DIRTY !!!!!
?>
<ul>
<?php foreach ($user_list as $user): ?>
  <li>
    <a href=<?php echo "http://localhost/RestClient/index.php?action=get_user&id=" . $user   ["id"]  ?> alt=<?php echo "user_" . $user_["id"] ?>><?php echo $user["name"] ?></a>
</li>
<?php endforeach; ?>
</ul>
<?php
}
?> 
1
  • <a href=<?php echo it's unquoted because you don't have quotes after href= Commented Nov 29, 2013 at 10:48

3 Answers 3

1
<a href="<?php echo "http://localhost/RestClient/index.php?action=get_user&id=" . $user   ["id"]  ?>" alt="<?php echo "user_" . $user_["id"] ?>"><?php echo $user["name"] ?></a>

OR

<a href=<?php echo "'http://localhost/RestClient/index.php?action=get_user&id=" . $user   ["id"]."'"  ?> alt=<?php echo "'user_" . $user_["id"]."'" ?>><?php echo $user["name"] ?></a>
Sign up to request clarification or add additional context in comments.

Comments

1

I have updated your code, and it works well

<?php echo "<a href='http://localhost/RestClient/index.php?action=get_user&id='".$user['id']."' alt=user_'".$user['id']."'>"; ?><?php echo $user["name"] . "</a>"; ?>

Comments

0

May be helpful.

<a herf="http://localhost/RestClient/index.php?action=get_user&id="<?php echo $user["id"]; ?> alt="user_"<?php echo $user_["id"]; ?> > <?php echo $user["name"]; ?> </a>

or

<a herf="http://localhost/RestClient/index.php?action=get_user&id=<?php echo $user['id']; ?>" alt="user_<?php echo $user_['id']; ?>" > <?php echo $user["name"]; ?> </a>

Comments

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.