0

I am passing a variable value from database to one PHP page through URL and that variable value contains spaces in it. The values before the space is passing successfully but not after the space. What can i do to pass the complete value? The URL concatenation i've done is shown in below code. Please help!

<?php $linking = "appointment.php?name=";
$linking .="$row[5]";
echo "<a href=$linking>BOOK AN APPOINTMENT</a>" 
?>

4 Answers 4

3

Encode your values using urlencode()

Sign up to request clarification or add additional context in comments.

Comments

2

urlencode should do it. Also put double quotes around the href.

<?php $linking = "appointment.php?name=";
$linking .= urlencode($row[5]);
echo "<a href=\"$linking\">BOOK AN APPOINTMENT</a>" 
?>

A further improvement would be to add htmlspecialchars to protect against & characters in $row[5] and against " in it:

<?php $linking = "appointment.php?name=";
$linking .= urlencode($row[5]);
echo "<a href=\"".htmlspecialchars($linking, ENT_QUOTES)."\">BOOK AN APPOINTMENT</a>" 
?>

1 Comment

Yes @adder i appreciate your answer it gave me perfect solution!
0

Replace the space with a joker like "-" or anything you want, with str_replace for an example. Then when you retrieve it just replace the joker by space.

Comments

0

You can also try the rawurlencode.This will encode spaces as %20 instead of +.

urlencode encodes spaces as + symbols while rawurlencode encodes as %20.

<?php 
$linking = "appointment.php?name=";
$linking .=rawurlencode($row[5]);
echo "<a href=$linking>BOOK AN APPOINTMENT</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.