showtime
showtime

Reputation: 1462

Pass values (including spaces) to another page in PHP

I am trying to pass id and username to next page via url and its working if the username has no spaces like "username", however when there is a space like "user name", only the name until the space will be passed to next page.

Here is my code:

<td>
    <?php echo '<a href=selectedCustomer.php?user_name='.$user["username"]. "&user_id=" . $user["id"] . '>' . $user["username"] . '</a>'; ?>
</td>

Upvotes: 0

Views: 223

Answers (1)

fonini
fonini

Reputation: 3341

You need to urlencode() the parameter first:

<?php 
echo '<a href=selectedCustomer.php?user_name='.urlencode($user["username"]). "&user_id=" . $user["id"] . '>' . $user["username"] . '</a>'; 
?>

Upvotes: 1

Related Questions