MidOhioIT Posted January 8, 2010 Share Posted January 8, 2010 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 More sharing options...
cags Posted January 8, 2010 Share Posted January 8, 2010 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 https://forums.phpfreaks.com/topic/187703-passing-a-parameter-in-a-link/#findComment-990939 Share on other sites More sharing options...
MidOhioIT Posted January 8, 2010 Author Share Posted January 8, 2010 cags, thanks for your help. I notice that it puts a "+" on it. so i just had to do a $business = str_replace('+', ' ', $business); to get rid of the place and allow spaces again. this worked, thank you for your help ! Link to comment https://forums.phpfreaks.com/topic/187703-passing-a-parameter-in-a-link/#findComment-990946 Share on other sites More sharing options...
cags Posted January 8, 2010 Share Posted January 8, 2010 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 https://forums.phpfreaks.com/topic/187703-passing-a-parameter-in-a-link/#findComment-990956 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.