ded Posted January 19, 2009 Share Posted January 19, 2009 Hello All, I have names that are linkable to show information about a specific person. Some names have an apostrophe in them and the URL is not working. This URL works fine: http://www.website.com/information.php?name=John Doe This URL does not work: http://www.website.com/information.php?name=Brian O'Connor How do I go about fixing this? Do I have to eliminate the apostrophe in the database? Regards, DED Quote Link to comment https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/ Share on other sites More sharing options...
trq Posted January 19, 2009 Share Posted January 19, 2009 urlencode Quote Link to comment https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/#findComment-740706 Share on other sites More sharing options...
ded Posted January 23, 2009 Author Share Posted January 23, 2009 The page is still not loading. $url = urlencode($name); The $url is showing as http://www.website.com/personal.php?name=Brian+O%27Connor Error: Expected ')' All the other names with the ' works fine. Quote Link to comment https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/#findComment-744224 Share on other sites More sharing options...
gevans Posted January 23, 2009 Share Posted January 23, 2009 You need to show us the page code Quote Link to comment https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/#findComment-744238 Share on other sites More sharing options...
premiso Posted January 23, 2009 Share Posted January 23, 2009 Upon calling back $_GET['name'] you would need to use urldecode, but as gevens pointed outyou have a syntax error and it is not in the 1 line of code you posted. Quote Link to comment https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/#findComment-744245 Share on other sites More sharing options...
ded Posted January 23, 2009 Author Share Posted January 23, 2009 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <script type="text/JavaScript"> function poptastic(url) { newwindow=window.open(url,'name','height=600,width=820,scrollbars=yes,resizable=yes'); if (window.focus) {newwindow.focus()} } //--> </script></head> <body> <?php $dbh=mysql_connect ("localhost", "username", "password") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("database"); $field1 = $_GET['field1']; $field2 = $_GET['field2']; $query = "SELECT * FROM profile"; $result = mysql_query($query,$dbh) or die(mysql_error()); while($row = mysql_fetch_array($result)) { $name = $row['name']; $url = urlencode($name); echo "<a href=\"javascript:poptastic('http://www.website.com/profile.php?playername=$url');\">$name</a>"; } ?> </body> </html> Regards, DED Quote Link to comment https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/#findComment-744251 Share on other sites More sharing options...
premiso Posted January 23, 2009 Share Posted January 23, 2009 while($row = mysql_fetch_array($result)) { $name = $row['name']; $url = urlencode($name); echo '<a href="javascript:poptastic(\'http://www.website.com/profile.php?playername={$url}\');">{$name}</a>'; } Should solve your syntax issue. Quote Link to comment https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/#findComment-744255 Share on other sites More sharing options...
ded Posted January 23, 2009 Author Share Posted January 23, 2009 Still not working......hmmm. Do i have to eliminate the ' from all names for this to work? DED Quote Link to comment https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/#findComment-744273 Share on other sites More sharing options...
premiso Posted January 23, 2009 Share Posted January 23, 2009 Still not working......hmmm. Do i have to eliminate the ' from all names for this to work? DED Posting the error and line may help out a bit more. Given the above, I do not see a php Syntax error. Quote Link to comment https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/#findComment-744290 Share on other sites More sharing options...
gevans Posted January 23, 2009 Share Posted January 23, 2009 while($row = mysql_fetch_array($result)) { $name = $row['name']; $url = urlencode($name); echo '<a href="javascript:poptastic(\'http://www.website.com/profile.php?playername={$url}\');">{$name}</a>'; } Should solve your syntax issue. You're using variables inside single quotes... echo "<a href=\"javascript:poptastic('http://www.website.com/profile.php?playername={$url}');\">{$name}</a>"; Quote Link to comment https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/#findComment-744296 Share on other sites More sharing options...
premiso Posted January 23, 2009 Share Posted January 23, 2009 while($row = mysql_fetch_array($result)) { $name = $row['name']; $url = urlencode($name); echo '<a href="javascript:poptastic(\'http://www.website.com/profile.php?playername={$url}\');">{$name}</a>'; } Should solve your syntax issue. You're using variables inside single quotes... echo "<a href=\"javascript:poptastic('http://www.website.com/profile.php?playername={$url}');\">{$name}</a>"; Yea I feel like a tard. I forgot that the { and } do not parse out under single quotes. Quote Link to comment https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/#findComment-744308 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.