Jump to content

passing a parameter in a link


MidOhioIT

Recommended Posts

Can someone tell me why the following code is not working correctly?  The scenerio is that the variable $business_name = "teeth fixes"  it only gets the first word and not the entire phrase.  If I do "teeth_fixes" then it will get the entire phrase.  For some reason when it hits the space it cuts the rest off.  The same variable business name just before the "</a>" in the link has the whole name just fine, it has something to do with the param function i guess?? I even tried to do the link different like this:

echo"<tr>                                   
                <td><a href=show_coupon.php?business=".$business_name.">$business_name</a>
                <td>                                        
        </tr>";

 

But that did not seem to work either.

 

Here is the code that is breaking the words.  Not sure why or how to fix it

while ($row = mysql_fetch_array($cat_coupons)) 
                                 {
                                $business_name = $row["business_name"];
								                          echo"<tr>
                                           <td><a href=show_coupon.php?business=$business_name>$business_name</a></td>
                                        </tr>";
	 }

 

Any help in advanced is appriciated.

Link to comment
https://forums.phpfreaks.com/topic/187703-passing-a-parameter-in-a-link/
Share on other sites

A space is not a valid URL character. You will need to use something like urlencode.

 

echo
"<tr>                                   
   <td><a href=show_coupon.php?business=".urlencode($business_name).">$business_name</a><td>                                        
</tr>";

Then on show_coupon.php you can use urldecode to put the value back as was.

Use...

 

$business = urldecode($business);

 

The urlencode function replaces more characters than just the space. There's a good chance you won't have those characters in your string, but it's always best to stick to the pre-designed functions where possible. Don't forget to mark the topic as solved by clicking 'Mark Solved' (bottom left corner of threads you start).

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.