Jump to content

Apostrophe causing problems in URL


ded

Recommended Posts

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

 

 

Link to comment
https://forums.phpfreaks.com/topic/141506-apostrophe-causing-problems-in-url/
Share on other sites

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

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.

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>";

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.

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.