Page 1 of 1

What wrong with my code here? T_String error?

Posted: Thu Jul 13, 2006 9:20 am
by joseph
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/sitename/public_html/php/feedback.php on line 2027

Code: Select all

if (mail($recipient,$subject,$message,$headers)) {
   echo '
Line 2027:

Code: Select all

<b>',Thank You $Title $FirstName $Lastname'</p><a href="www.sitename.com/english/thank_you.html">'Click Here,'</b>'; 
} else {
   echo '
   <a href="www.sitename.com/english/thank_you.html">',Back,'</a>';   
}
?>

Posted: Thu Jul 13, 2006 9:41 am
by JayBird
Show more of your code

Posted: Thu Jul 13, 2006 9:46 am
by Chris Corbyn
Well I can see the problem before you post further code.

What string delimters are you using? Single quotes or double quotes? Either way you have them in your string unescaped. Use backslashes to escape those characters ;)

Posted: Thu Jul 13, 2006 9:49 am
by MarK (CZ)
Also, I don't understand why are there so many single quotes? It seems to me that on both sides of many quotes is text that should be enclosed in some quotes.

IMO this should do it:

Code: Select all

if (mail($recipient,$subject,$message,$headers)) {
  echo "<b>Thank You $Title $FirstName $Lastname</p>".
       "<a href=\"www.sitename.com/english/thank_you.html\">Click Here</b>";
} else {
   echo "<a href=\"www.sitename.com/english/thank_you.html\">Back</a>";
}

Posted: Thu Jul 13, 2006 10:12 am
by joseph
Thanks guys! :D Worked fine now. Does the double quote and single quote has the same functions?

Posted: Thu Jul 13, 2006 10:15 am
by JayBird
Examples

Code: Select all

$name = "Mark";

echo "My name is $name";

// outputs: My name is Mark

Code: Select all

$name = "Mark";

echo 'My name is $name';

// outputs: My name is $name

Code: Select all

$name = "Mark";

echo 'My name is '.$name;

// outputs: My name is Mark

Posted: Thu Jul 13, 2006 10:42 am
by Ward
Instead of using the echo statement, you can always use the ?> <? tags to output HTML. This way you don't have to worry about escaping quotes, and you will get HTML syntax coloring in your editor.

Pimptastic's example of double vs single quotes is good. Double quotes will resolve variables to their values, single quotes will not.

For example:

Code: Select all

if (mail($recipient,$subject,$message,$headers))
{
?>
     <b>Thank You <?=$Title?> <?=$FirstName?> <?=$Lastname?></p>
     <a href="www.sitename.com/english/thank_you.html">Click Here</b>
<?
} else {
?>
     <a href="www.sitename.com/english/thank_you.html">Back</a>  
<?
}
?>
It's probably not the best or most attractive method, but it does work. I use it when I need to output large blocks of HTML, mostly because of the HTML syntax coloring thing.

Posted: Thu Jul 13, 2006 11:00 am
by RobertGonzalez
Single quotes = string literal. Whatever is in the single quotes gets echo'ed as such.

Double quotes = parsed/evaluated string.

There is a lot of good information on strings in the PHP manual.

Posted: Fri Jul 14, 2006 6:29 am
by joseph
@Everah, @Ward, @Pimptastic, @MarK (CZ):

Thanks for all your help! :D

Posted: Fri Jul 14, 2006 6:54 am
by MarK (CZ)
Everah wrote:Single quotes = string literal. Whatever is in the single quotes gets echo'ed as such.
Except \' (') and \\ (\) entities :)

Posted: Fri Jul 14, 2006 8:54 am
by RobertGonzalez
MarK (CZ) wrote:
Everah wrote:Single quotes = string literal. Whatever is in the single quotes gets echo'ed as such.
Except \' (') and \\ (\) entities :)
Sorry, I should have mentioned that.