[SOLVED] Newbie unexpected T_VARIABLE 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
sabian
Forum Newbie
Posts: 6
Joined: Thu Oct 07, 2004 3:07 am

[SOLVED] Newbie unexpected T_VARIABLE error...

Post by sabian »

feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color] 


this is one of my first proper little php coding tests as im very new to php... ive got the following error:

Code: Select all

Parse error: parse error, unexpected T_VARIABLE
the error is on line 24. Ive had a look but cant seem to see a problem, have i just put an extra space in somewhere and thats causing the problem...

Code: Select all

<?php

$initial_entry_date = 001;

$today = date('Ymd');
if (isSet($_GET['date'])) {
	if ($_GET['date'] < $initial_entry_date) {
		$date = $inital_entry_date;
	} elseif ($_GET['date'] > $today) {
	$date = $today;
	} else {
	$date = $_GET['date'];
	}
} else {
	$date = $today;
}

$title_msg = $date;
$header_msg = "Weblog entry for $date";

$prevdate = $date - 1;
$nextdate = $date + 1;
if ($date == $initial_entry_date) {
	$flipbar = "\n<P CLASS="next"><A HREF="$PHP_SELF?date=$nextdate">Next --></A></P>\n";
} elseif ($date == $today) {
	$flipbar = "\n<P CLASS="previous"><A HREF="$PHP_SELF?date=$prevdate"><-- Previous</A></P>\n";
} else {
	$flipbar = "\n<TABLE BORDER=0><TR><TD WIDTH="50%"
ALIGN="left"><SPAN CLASS="previous"><A 
HREF="$PHP_SELF?date=$prevdate"<-- Previous</A></SPAN></TD><TD 
WIDTH="50%" ALIGN="right"><SPAN CLASS="next"><A
HREF="$PHP_SELF?date=$nextdate">Next --
></A></SPAN></TD></TR></TABLE>\n";
}

include_once('header.inc');

echo $flipbar;
if (file_exists($DOCUMENT_ROOT."entries/$date.txt")) {
	include($DOCUMENT_ROOT."entries/$date.txt");
} else {
	include("default.txt");
}
echo $flipbar;

include_once('footer.inc');
?>
Any help for me the newbie much appreciated....


feyd | Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

first before you get into to much trouble try using the php button to wrap your code so it is easier to read.
feyd be gentle.
second
on this line

Code: Select all

<?php
if ($date == $initial_entry_date) {
   $flipbar = "\n<P CLASS="next"><A HREF="$PHP_SELF?date=$nextdate">Next --></A></P>\n"; 
?>
you seem to have missed escaping the first " of your HREF.
same thing happens on the next line as well.

thirdly you might want to use lower case for your html tags as that would move you more down the road to be xhtml complaint.

hope that fixes your error.
sabian
Forum Newbie
Posts: 6
Joined: Thu Oct 07, 2004 3:07 am

Post by sabian »

sorry im obviously not awake this morning...

the only difference i can see is that the \ after the $nextdate has been removed... i cant exactly see why the A HREF isnt closing....

am i obviously missing something and being stupid... either that or im getting confused between lines....
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Remember that in double quoted strings you need to make sure that you escape (put a \ in front of) any double quotes, otherwise PHP thinks the string has ended, note the difference in syntax colouring of the following:

Code: Select all

$flipbar = "\n<P CLASS="next"><A HREF="$PHP_SELF?date=$nextdate">Next --></A></P>\n";
and

Code: Select all

$flipbar = "\n<P CLASS="next"><A HREF="$PHP_SELF?date=$nextdate">Next --></A></P>\n";
Mac
sabian
Forum Newbie
Posts: 6
Joined: Thu Oct 07, 2004 3:07 am

Post by sabian »

hmmm have changed and closed the A HREF but still doesnt work... im obviously having a blond moment lol its too early in the morning. Any chance you could post the full original code again that i supplied with the modification so i can see where im going wrong...

its going to take me a while to learn this php thing :p
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You do have a similar issue throughout the code - just follow the error messages and make sure all the double quotes in the HTML are escaped.

Mac
sabian
Forum Newbie
Posts: 6
Joined: Thu Oct 07, 2004 3:07 am

Post by sabian »

How does this look... as far as i can see ive solved the problem... but the error is still there for some reason :/

Code: Select all

<?php 

$initial_entry_date = 001; 

$today = date('Ymd'); 
if (isSet($_GET['date'])) { 
   if ($_GET['date'] < $initial_entry_date) { 
      $date = $inital_entry_date; 
   } elseif ($_GET['date'] > $today) { 
   $date = $today; 
   } else { 
   $date = $_GET['date']; 
   } 
} else { 
   $date = $today; 
} 

$title_msg = $date; 
$header_msg = "Weblog entry for $date"; 

$prevdate = $date - 1; 
$nextdate = $date + 1; 
if ($date == $initial_entry_date) { 
   $flipbar = "\n<P CLASS="next"><A HREF="$PHP_SELF?date=$nextdate">Next --></A></P>\n";
} elseif ($date == $today) { 
   $flipbar = "\n<P CLASS="previous"><A HREF="$PHP_SELF?date=$prevdate"><-- Previous</A></P>\n"; 
} else { 
   $flipbar = "\n<TABLE BORDER=0><TR><TD WIDTH="50%" 
ALIGN="left"><SPAN CLASS="previous"><A 
HREF="$PHP_SELF?date=$prevdate"><-- Previous</A></SPAN></TD><TD 
WIDTH="50%" ALIGN="right"><SPAN CLASS="next"><A 
HREF="$PHP_SELF?date=$nextdate">Next -- 
></A></SPAN></TD></TR></TABLE>\n"; 
} 

include_once('header.inc'); 

echo $flipbar; 
if (file_exists($DOCUMENT_ROOT."entries/$date.txt")) { 
   include($DOCUMENT_ROOT."entries/$date.txt"); 
} else { 
   include("default.txt"); 
} 
echo $flipbar; 

include_once('footer.inc'); 
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Um, you've removed escaping, not added it? You need to change things like:

Code: Select all

$flipbar = "\n<P CLASS="next"><A HREF="$PHP_SELF?date=$nextdate">Next --></A></P>\n";
to

Code: Select all

$flipbar = "\n<P CLASS="next"><A HREF="$PHP_SELF?date=$nextdate">Next --></A></P>\n";
Mac
sabian
Forum Newbie
Posts: 6
Joined: Thu Oct 07, 2004 3:07 am

Post by sabian »

thanks for your help... ive managed to get the script working correctly.

Now i just need to work out why the page doesnt display at all!!!

http://www.voisd.com/weblog/weblog.php

thanks for your help!!!
Post Reply