PDA

View Full Version : Problem with Quotes with PHP/Javascript


Jack101
12-31-2002, 11:38 AM
Hi All,
Thanks in advance for any help you can give with this.

I have the following which links from frame A to frames B and C when an item in the frame A list is selected.

while ($row= mysql_fetch_array($result))
{$id=$row['id'];
$name=$row['name'];
$otherdata=$row['otherdata'];
echo("<tr><td><a href=\"javascript:
void(parent.FrameB.location='FrameB.php?id=$id&name=$name&otherdata$otherdata');
void(parent.FrameC.location='FrameC.php?=$id');
\">&nbsp;".$name."</a></td></tr>");}

My problem is that if the value of $name has a single quote the link doesn't work. I assume this is because it is confusing the javascript.
If I apply addslashes on the variable:
$name=addslashes($name);
I just get a value of, for example, O[backslash]'Keefe (for O'Keefe). The quote is still there and still seems to confuse the javascript, and it displays with the '[backslash]' in the frame A list.
I have magic quotes on.
(I am writing '[backslash]' rather than the real thing as this editor seems to ignore the real thing?? - it has also put a space between 'java' and 'script' above - I didn't key it that way???)
Thanks, Jack.

firepages
12-31-2002, 12:33 PM
Hi you should be able to remove the escaping slash with javascript - unescape() (is a guess ?)

its really a javascript question so I am moving this thread there, hang on...

whammy
12-31-2002, 06:44 PM
Try this:


while ($row= mysql_fetch_array($result))
{$id=$row['id'];
$name=$row['name'];
$otherdata=$row['otherdata'];
echo("<tr><td><a href=\"javascript:
void(parent.FrameB.location=escape('FrameB.php?id=$id&name=$name&otherdata$otherdata'));
void(parent.FrameC.location=escape('FrameC.php?=$id'));
\">&nbsp;".$name."</a></td></tr>");}


Hope I got everything in the right place... ;)

Jack101
01-02-2003, 08:53 AM
Whammy, thanks, tried it but although the links nearly worked, i.e. they were invoked, I got a 'Forbidden... don't have access to the page ...' message in the linked to frames.

What does escape() do?

I have actually got PHP addslashes to work, but that is also giving me some other problems, so if I can get escape to work that may be better.

Cheers, Jack.

glenngv
01-02-2003, 09:50 AM
don't know php, but try this:

void(parent.FrameB.location='FrameB.php?id=$id&name=' + escape($name) + '&otherdata$otherdata');

if that doesn't work, try replacing all occurrences of single quote to %27 in the php variable $name before inserting in the url and then retain the original javascript code.