Forum Moderators: coopster

Message Too Old, No Replies

Help With This Code

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

         

xKroniK13x

2:59 am on Feb 22, 2010 (gmt 0)

10+ Year Member



Hi, I'm coding a new website. I am new to this site, but I hope that doesn't effect anything.

Anyways, I want to make it so it has actions and it will change an iframe of the website. I have this as the code:

<?php
$action = $_GET['action'];
if ($action == about) {
echo "<iframe src = aboutus.html width="415" height="398">
<p>Your browser does not support the correct coding for this website.</p>
</iframe>";
}
elseif ($action == designs) {
echo "<iframe src = designs.html width="415" height="398">
<p>Your browser does not support the correct coding for this website.</p>
</iframe>";
}
else {
echo "<iframe src = homecontent.php width="415" height="398">
<p>Your browser does not support the correct coding for this website.</p>
</iframe>";
}
?>


And, I get this error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /www/cjdesigns/index3.php on line 91


Line 91 of the code is:
  echo "<iframe src = aboutus.html width="415" height="398">


Any ideas? Thanks in advanced!

Readie

3:23 am on Feb 22, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to Webmaster World xKroniK13x

Several syntax errors in this, I'd bold them or mark them out in some other way, unfortunatley it doesn't show well enough with bold, and adding all the comments in would be pointless:

<?php 
$action = $_GET['action'];
if($action == "about") {
echo '<iframe src="aboutus.html" width="415" height="398">
<p>Your browser does not support the correct coding for this website.</p>
</iframe>';
} elseif($action == "designs") {
echo '<iframe src="designs.html" width="415" height="398">
<p>Your browser does not support the correct coding for this website.</p>
</iframe>';
} else {
echo '<iframe src="homecontent.php" width="415" height="398">
<p>Your browser does not support the correct coding for this website.</p>
</iframe>';
}
?>




With code like:

echo "<iframe width="22">";


You're ending the echo quotations early with the HTML quotations for width - in essence:

echo "<iframe width="SYNTAX ERROR

You can either escape the quotations in the HTML:

echo "<iframe width=\"22\">";


But that can be really annoying, so I personally consider it best to echo with single quotes (just remember to escape any single quotes you may need to use):

echo '<iframe width="22">';




if($action == about) {


This format can only be used for an integer variable, with a string you need to add quotes around the string, like so:

if($action == "about") {




And finally, for future reference, an unexpected T_STRING is a syntax error of some description, most often caused by a missing quotation or semi colon

xKroniK13x

3:29 am on Feb 22, 2010 (gmt 0)

10+ Year Member



Okay, thank you. I will try that out and see what happens!

xKroniK13x

3:39 am on Feb 22, 2010 (gmt 0)

10+ Year Member



I'm not sure if double posting is against forum rules, sorry if it is, but the code now works perfect! Thanks a lot!