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
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.

Link to comment
Share on other sites

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).

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.