Forum Moderators: coopster

Message Too Old, No Replies

Form Error

         

contentmaster

12:35 pm on Apr 21, 2009 (gmt 0)

10+ Year Member



I am trying to customise a form by adding some html content in the echo section. I am receiving the following error message :

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/trial/public_html/forms.php on line 414

This is the part of the code that shows the error - line 414

++++++++++++++++++++++++++++++++++++

} else {
echo "<body><font face="Verdana" size="2">&nbsp;</font><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="756">
<tr>
<td width="179">
<a href="http://www.mydomain/index.htm">
<img border="0" src="http://www.mydomain.com/images/logo.gif" alt=""></a></td>
<td width="577">
<p align="right"><b><font face="Verdana" size="2"><a href="http://www.mydomain.com/index.htm">
<font color="#AD1818">Home</font></a></font></b></td>
</tr>
</table>
<table border="0" width="758" height="250">
<tr>
<td width="738" height="33" colspan="2" valign="top">
<p align="center"><b><font face="Arial" size="4">Thank You for your
enquiry. We will get back to you very soon. </font>
<font face="Arial" size="4" color="#ad1818">&nbsp;</font></b></td>
</tr>
</table>
</body>\n";
exit;
}

// <---------- THE END ----------> //

henry0

2:15 pm on Apr 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I do not know if that will be it, at first sight you need to get rid of all double quotes and replace them by simple quote
echo"<width='100%' align='center'>";
or use escape, but the above one is simpler ans easier to read.
echo"<width=\"100%\" align=\"center\">";

rocknbil

10:22 pm on Apr 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem begins here . . .

"<body><font face="Verdana" size="2">

PHP thinks your string ends at the first opening quote of the font attribute.

Personally I like to validate all script output, and although single quotes are "valid" I use the classic style of double quoted attributes in html, so I use single quotes for hard-coded output and concatenate for inline variables.

echo '<body><font face="Verdana" size="2">'.$some_var.</font>';

But if you have a lot of inline variables, it may be easier to take henry0's approach:

echo "<body><font face=\"Verdana\" size=\"2\">$some_var</font>";

Which gives the "toothpick syndrome." :-) Since you're using font tags which won't validate anyway, either should be fine.

I'll never understand why PHP doesn't have the equivalent of perl's multiline qq, in which all these go away. or does it?

contentmaster

10:13 am on Apr 29, 2009 (gmt 0)

10+ Year Member



Okay..will try henry0's approach .... no double quotes in between...only in the beginning and at the end...correct?

henry0

11:15 am on Apr 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



rocknbil
has written about it too
that you may either use single quote between double quotes
or you may escape a double quote as \"aaaa\"
I am not sure that this is your problem
have you try to add by the top of your page:
error_reporting(E_ALL);
and report your findings

rocknbil

4:07 pm on Apr 29, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



.... no double quotes in between...

No don't do that.

echo "<font face=Verdana size=2>$some_var</font>";

While this "works," unquoted attributes are a really bad habit to form. As an example, what if you have CSS classes named "right-align" and "emphasis-style" (color= red) and to apply both without writing a new selector, you would do

<p style="right-align emphasis-style">I'm red and right-aligned</p>

But without quoting,

<p style=right-align emphasis-style>I'm red and right-aligned</p>

This would most likely fail, and the absence of quotes could cause whole blocks of text to disappear in the browser even if it's in the source code.

I's still recommend the single quote or "toothpick syndrome" escape approach. As a programmer you just want to get the job done, but there's nothing wrong with getting it done right. Get your head around how PHP manages raw text and quoting and it will become very easy to manage.

By the way my single-quoted example had an error, was missing a single quote (doh.)

echo '<body><font face="Verdana" size="2">'.$some_var.'</font>';