Hi, new to php, why do I get this syntax error?

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
patriotofgod
Forum Newbie
Posts: 4
Joined: Sat Dec 13, 2008 6:36 pm

Hi, new to php, why do I get this syntax error?

Post by patriotofgod »

I have just completed my new domain and I am trying to implement a short php script on it. When I am trying to load the page, I get an error code. I had gotten the php code from another developer on another website, and its suppose to work. Here is the website coding.

Code: Select all

<?php
 
$site1 = "http://www.<span style='color:blue' title='I&#39;m naughty, are you naughty?'>smurf</span>.com";
$affiliate_link = "http://www.webcams.com/link.php?reseller=craigsbatter45&rev=0&type=2&misc1=&misc2=&_u=/index.php?page=join&mcat_id=";
 
if($_SERVER['HTTP_REFERER'] == $site1)
{
    echo "<body onload="javascript&#058;frmClickTracking.submit();">";
    echo "<form action="" . $affiliate_link . "" method="post" name="frmClickTracking">";
    echo "</form>";
}
 
?>
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
 
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
 
body {
    background-color: #1F1B1C;
}
-->
</style></head>
 
<body>
<div align="center"><img src="file:///C|/Users/donkeykongbutter/Documents/affilate landing page right size copy.jpg" width="1200" height="879" border="0" usemap="#Map" />
    <map name="Map" id="Map">
      <area shape="rect" coords="426,329,1137,457" href="http://www.webcams.com/link.php?reseller=craigsbatter45&rev=0&type=2&misc1=&misc2=&_u=/index.php?page=join&mcat_id=" />
    </map>
</div>
</body>
</html>
 
Upon loading the webpage in the browser, I get the following syntax error...

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/content /w/e/b/webcamsdr/html/index.php on line 8

and line 8 is :

echo "<body onload="javascript:frmClickTracking.submit();">";

Am I missing something? I only have this one page on my website.
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: Hi, new to php, why do I get this syntax error?

Post by jaoudestudios »

echo "<body onload="javascript:frmClickTracking.submit();">";
You cant use quotes like that. You need to escape them.
i.e.

Code: Select all

echo "<body onload=\"javascript&#058;frmClickTracking.submit();\">";
or use single quotes...
(option 1)

Code: Select all

echo "<body onload='javascript&#058;frmClickTracking.submit();'>";
(option 2)

Code: Select all

echo '<body onload="javascript&#058;frmClickTracking.submit();">';
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Hi, new to php, why do I get this syntax error?

Post by califdon »

It's just a matter of quote marks. Your code:

Code: Select all

echo "<body onload="javascript&#058;frmClickTracking.submit();">";
is interpreted by PHP as echo "<body onload=" and then that's the end of the string! Rewrite that this way:

Code: Select all

echo "<body onload='javascript&#058;frmClickTracking.submit();'>";
or this way:

Code: Select all

echo "<body onload=\"javascript&#058;frmClickTracking.submit();\">";
The backslash "escapes" the interpretation of those quote marks as string delimiters.

[Edit: HaHa! You beat me to it, jaoudestudios!]
patriotofgod
Forum Newbie
Posts: 4
Joined: Sat Dec 13, 2008 6:36 pm

Re: Hi, new to php, why do I get this syntax error?

Post by patriotofgod »

Hey, thanks alot
Post Reply