Reputation: 243
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
}
?>
Upvotes: 0
Views: 471
Reputation: 576
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>
Upvotes: 0
Reputation: 10131
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>"; ?>
Upvotes: 1
Reputation: 1422
<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>
Upvotes: 1