Javascript inside PHP code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ms.Jemi
Forum Newbie
Posts: 6
Joined: Thu Mar 03, 2011 1:50 am

Javascript inside PHP code

Post by ms.Jemi »

Hi guyz...
I need some with my php code.
I want to have a pop window in my a href link inside the php code.
But I have problems coz there is an error regarding with my script inside the php
Here is my code

echo "<td><img src=".$img[$x]." width='250' height='250'><br>".'<input type="checkbox" name="formVotes[]" value="'.$canId[$x].'" /><br>'.$fName[$x]."&nbsp;".$mName[$x]."&nbsp;".$lName[$x]."&nbsp;".'</input><br> <a href="viewprofile.php?canid='.$canId[$x].'" target="popupWin" onsubmit="return openWindow('addProfile.php', 'popupWin', 1000, 500);">View Profile</a></td>';

I really need your help guyz...
Thank you in advance!
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: Javascript inside PHP code

Post by social_experiment »

What type of error are you receiving? A quick look at your code shows that you aren't escaping the quotation marks correctly.

Code: Select all

<?php
 // example 1
 echo "<img src=\"path/to/file\" width=\"100\" height=\"100\" />";
 // example 2
 echo '<img src="path/to/file" width="100" height="100" />';
 // example 3
 echo 'Hello \'World\' ';
?>
If you are encassing your statements in double quote marks (") any double quotes inside the statement has to be escape, like in example 1. Same goes for single quotation marks (per example 3). I find that it's easier to use single quotes to encase when working with html where " is required i.e src="path/to/file".
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply