0

I'm having trouble with quotes in a line of the attached code.

It is part of a picture viewer. Picture data url "PicNotes" is read from mysql. I am attempting to enhance the result by adding a picture info pop-up but can't get the quotes right.

I have added some rem statements around 3 versions (attempts) to get it working.

    $data = mysql_query("SELECT * FROM $tbl_name WHERE type='$type' LIMIT $start, $limit_col_1");}
// Your while loop here
while($row = mysql_fetch_array($data))
{//REM If there is no info don't show the info link
    if ($row[PicNotes]) {
//  $icon=<a href="JavaScript:Popup('notes/$row['PicNotes']');"> <img src='images/info.png'></a>; //REM This line was the original call for the pop-up script
//  $icon = "<a href=notes/tempest_series.php><img src=images/info.png></a>"; //REM This line works but does not have any of the Jarvascript or URL variable from the DB
//  $icon = "<a href=notes/$row[PicNotes]><img src=images/info.png></a>"; //REM This  line doesn't crash but the URL is corrupted
    $icon = "<a href="JavaScript:Popup(notes/$row[PicNotes]);"><img src=images/info.png></a>"; //REM This line crashes with an "Unexpected T_STRING error 
    }else{
    $icon='';}
// Display LHS Thumbnail and Viewer Pic Data

    echo "<a href='images/".$row['vfile']."' rel='enlargeimage::mouseover' rev='loadarea' title='&lt;b&gt;".$row['Title']."&lt;/b&gt;&lt;br /&gt;".$row['Medium']." &nbsp; &nbsp; &nbsp; ".$row['iw']." x ".$row['ih']." cm. $icon'><img border='1' src='images/".$row['tnfile']."
    ' alt='' width='".$row['tnx']."' height='".$row['tny']."' class='tn' /></a><br />";

}

Please can somebody put me on the right track.

1
  • When you begin "<a href=" you closed on that ". Try this sort of format. $var = "<a href='javascript:'>link</a>"; Commented Apr 23, 2014 at 18:53

2 Answers 2

1

1) Escape the inner quotes:

$icon = "<a href=\"JavaScript:Popup(notes/$row[PicNotes])\"><img src=images/info.png></a>";

2) Use single quotes:

$icon = "<a href='JavaScript:Popup(notes/$row[PicNotes])'><img src=images/info.png></a>";
Sign up to request clarification or add additional context in comments.

3 Comments

Escaping the inner quotes does stop the crashing, however the resulting link is corrupted, it has a ";" appended. Deleting the ";" in the code produces a "correct" link but this results in an error - Error on Page - notes is undefined. Using single quotes caused major corruption to the resulting display
Just delete the semi-colon.
Thanks @John Conde but I had already covered that in mu previous comment.
0

Use curly braces ({}) for better variable concatenation

$icon="<a href=\"JavaScript:Popup('notes/{$row[PicNotes]}');\"><img src=\"images/info.png\"></a>";

1 Comment

Thanks @kangaswad but that doesn't help. I still get a browser error "'notes' is undefined" If I leave the semicolon in then the it gets added to the URL, I also have to remove the single quotes or the picture viewer is corrupted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.