Hey guys im really new to php and i had it all worked out untill this came along

it says this

Parse error: syntax error, unexpected T_STRING in /home/tattie/public_html/index.php on line 1

i really really dont know what to do and i would be so grateful if someone could tell me what is wrong

here is the code

<!--THIS INCLUDES HEADER.PHP--><? php get_header(); ?><!-- END -->

<div class="side"><?php if (have_posts()) : ?>
<?php $post = $posts[0]; // Thanks Kubrick for this code ?>

<?php if (is_category()) { ?>
<h3><?php _e('Archive for '); echo single_cat_title(); ?></h3>

<?php } elseif (is_day()) { ?>
<h3><?php _e('Archive for '); the_time('F j, Y'); ?></h3>

<?php } elseif (is_month()) { ?>
<h3><?php _e('Archive for '); the_time('F, Y'); ?></h3>

<?php } elseif (is_year()) { ?>
<h2><?php _e('Archive for '); the_time('Y'); ?></h2>

<?php } elseif (is_author()) { ?>
<h3><?php _e('Author Archive'); ?></h3>

<?php } elseif (is_search()) { ?>
<h3><?php _e('Search Results'); ?></h3>
<?php } ?>
<?php while (have_posts()) : the_post(); ?>

<!--TITLE TAG-->
<h1><?php the_title(); ?></h1>
<!--END-->


<!--TIME DATE CATEGORY WORDS-->
<h2><?php the_time('F jS, Y'); ?> by <?php the_author(); ?>  &nbsp;  <?php comments_popup_link(__('0 Comments'), __('1 Comment'), __('% Comments'), 'commentslink', __('sorry, Comments off for this post.')); ?> &nbsp;  <BR>
Filed Under: <?php the_category(', ') ?> &nbsp;
</h2>
<!--END-->

<?php if (is_search()) { ?>
<?php the_excerpt() ?>
<?php } else { ?>
<?php the_content(__('Read more &#187;')); ?>


<!--COMMENTS TAG-->

<!--END-->
<br /> <br />

<?php comments_template(); // Get wp-comments.php template ?>

<?php } ?>

<!--
<?php trackback_rdf(); ?>
-->

<?php endwhile; ?>
<?php posts_nav_link('', __(''), __('&laquo; Previous entries')); ?>
<?php posts_nav_link('  ', __(''), __('')); ?>
<?php posts_nav_link('', __('Next entries &raquo;'), __('')); ?>

<?php else : ?>
<h3><?php _e('Not Found'); ?></h3>
<p><?php _e('Sorry, but no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>

<!--THIS INCLUDES FOOTER.PHP-->
<?php get_footer(); ?><!-- END -->

Recommended Answers

All 22 Replies

<div class="side"><?php if (have_posts()) : ?>
Notice the : after posts())
change this to ;

Look through code for additional errors as notated between lines
////////////////
///////////////

Hey guys im really new to php and i had it all worked out untill this came along

it says this

Parse error: syntax error, unexpected T_STRING in /home/tattie/public_html/index.php on line 1

i really really dont know what to do and i would be so grateful if someone could tell me what is wrong

here is the code

<!--THIS INCLUDES HEADER.PHP--><? php get_header(); ?><!-- END -->
/////////////
Above make sure you chnge <? php to <?php   note no spacing
///////////////
<div class="side"><?php if (have_posts()) : ?>
<?php $post = $posts[0]; // Thanks Kubrick for this code ?>

<?php if (is_category()) { ?>
/////////////
Above need to end your php with a ; ?>
//////////////////
<h3><?php _e('Archive for '); echo single_cat_title(); ?></h3>

<?php } elseif (is_day()) { ?>
/////////////
Above need to end your php with a ;?>
///////////
<h3><?php _e('Archive for '); the_time('F j, Y'); ?></h3>

<?php } elseif (is_month()) { ?>
/////////////
Above need to end your php with a ;?>
//////////////////
<h3><?php _e('Archive for '); the_time('F, Y'); ?></h3>

<?php } elseif (is_year()) { ?>
/////////////
Above need to end your php with a ;?>
///////////////
<h2><?php _e('Archive for '); the_time('Y'); ?></h2>

<?php } elseif (is_author()) { ?>
/////////////
Above need to end your php with a ;?>
/////////////
<h3><?php _e('Author Archive'); ?></h3>

<?php } elseif (is_search()) { ?>
/////////////
Above need to end your php with a ;?>
//////////////
<h3><?php _e('Search Results'); ?></h3>
<?php } ?>
<?php while (have_posts()) : the_post(); ?>
/////////////////////////////////////////////////////////////////
Look above here, once again you have a : instead of an ;
/////////////////////////////////////////////////////////////////
<!--TITLE TAG-->
<h1><?php the_title(); ?></h1>
<!--END-->


<!--TIME DATE CATEGORY WORDS-->
<h2><?php the_time('F jS, Y'); ?> by <?php the_author(); ?>  &nbsp;  <?php comments_popup_link(__('0 Comments'), __('1 Comment'), __('% Comments'), 'commentslink', __('sorry, Comments off for this post.')); ?> &nbsp;  <BR>
Filed Under: <?php the_category(', ') ?> &nbsp;
/////////////
Above need to end your php with a ;?>
///////////////
</h2>
<!--END-->

<?php if (is_search()) { ?>
/////////////
Above need to end your php with a ;?>
///////////////
<?php the_excerpt() ?>
/////////////
Above need to end your php with a ;?>
////////////////
<?php } else { ?>
/////////////
Above need to end your php with a ;?>
///////////////
<?php the_content(__('Read more »')); ?>


<!--COMMENTS TAG-->

<!--END-->
<br /> <br />

<?php comments_template(); // Get wp-comments.php template ?>

<?php } ?>
/////////////
Above need to end your php with a ;?>
///////////////
<!--
<?php trackback_rdf(); ?>
-->

<?php endwhile; ?>
<?php posts_nav_link('', __(''), __('&laquo; Previous entries')); ?>
<?php posts_nav_link('  ', __(''), __('')); ?>
<?php posts_nav_link('', __('Next entries &raquo;'), __('')); ?>

<?php else : ?>
////////////////////
Above once again using a : instead of ;
////////////////

<h3><?php _e('Not Found'); ?></h3>
<p><?php _e('Sorry, but no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>

<!--THIS INCLUDES FOOTER.PHP-->
<?php get_footer(); ?><!-- END -->

Get rid of the space in between <? and php on line1. i.e replace
<? php get_header(); ?>
with
<?php get_header(); ?>

right ok i think i have most of it fixed..here is the new code

<!--THIS INCLUDES HEADER.PHP--><?php get_header() ;?><!-- END -->

<div class="side"><?php if (have_posts()) ;?>
<?php $post = $posts[0]; // Thanks Kubrick for this code ;?>

<?php if (is_category()) { ;?>
<h3><?php _e('Archive for '); echo single_cat_title() ;?></h3>
<?php } elseif (is_day()) { ;?>
<h3><?php _e('Archive for '); the_time('F j, Y') ;?></h3>

<?php } elseif (is_month()) { ;?>
<h3><?php _e('Archive for '); the_time('F, Y') ;?></h3>

<?php } elseif (is_year()) { ;?>
<h2><?php _e('Archive for '); the_time('Y') ;?></h2>

<?php } elseif (is_author()) { ;?>
<h3><?php _e('Author Archive') ;?></h3>

<?php } elseif (is_search()) { ;?>
<h3><?php _e('Search Results') ;?></h3>
<?php } ;?>
<?php while (have_posts()) ; the_post() ;?>

<!--TITLE TAG-->
<h1><?php the_title() ;?></h1>
<!--END-->


<!--TIME DATE CATEGORY WORDS-->
<h2><?php the_time('F jS, Y'); ;?> by <?php the_author(); ;?>  &nbsp;  <?php comments_popup_link(__('0 Comments'), __('1 Comment'), __('% Comments'), 'commentslink', __('sorry, Comments off for this post.')) ;?> &nbsp;  <BR>
Filed Under: <?php the_category(', ') ;?> &nbsp;
</h2>
<!--END-->

<?php if (is_search()) { ;?>
<?php the_excerpt() ;?>
<?php } else { ;?>
<?php the_content(__('Read more &#187;'));?>


<!--COMMENTS TAG-->

<!--END-->
<br /> <br />

<?php comments_template(); // Get wp-comments.php template ;?>

<?php } ;?>

<!--
<?php trackback_rdf() ;?>
-->

<?php endwhile: ?>
<?php posts_nav_link('', __(''), __('&laquo; Previous entries')): ?>
<?php posts_nav_link('  ', __(''), __('')): ?>
<?php posts_nav_link('', __('Next entries &raquo;'), __('')): ?>

<?php else ; ?>
<h3><?php _e('Not Found'); ?></h3>
<p><?php _e('Sorry, but no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>

<!--THIS INCLUDES FOOTER.PHP-->
<?php get_footer(); ?><!-- END -->

it says its wrong on line 55 but i cant see it

here if 55 btw
<?php endwhile: ?>

Try endwhile; on line 55. Note the semicolon instead of the colon

i have tried that as well and its still not working

its really weird it was working fine a few weeks ago and then the whole thing kinda died

Found your problem. You are starting the while loop with a semicolon instead of a colon. It's unusual to see while: and endwhile; in php. Most of us just use braces. Anyway here's what you need to do:

line 23: <?php while (have_posts()): the_post() ;?>
Also make sure 55 has the semicolon.

Also
Line 3 should be: <?php if (have_posts()) :?>
and
Line 60 should be: <?php ; else: ?>

thanks sooo much i have fixed most on it

now on line 60 it says there is somthing wrong

<?php else ;?>

Yeah sorry I updated my last post but I guess you didnt see it.

Line 3 should be: <?php if (have_posts()) :?>
and
Line 60 should be: <?php ; else: ?>

Line 3 should be: <?php if (have_posts()) :?>
and
Line 60 should be: <?php ; else: ?>

nope still not working

Try this on line 60:
<?php else: ?>

Also, do you have header.php in the same directory? If not, you'll get a Fatal Error: Call to undefined function get_header()

nope it is still coming up with

Parse error: syntax error, unexpected T_ELSE in /home/tattie/public_html/index.php on line 60

You are still getting parse errors? Read my last post again.

i am and the header is in the right directory

here is my code again and i dont have a clue what is wrong

<!--THIS INCLUDES HEADER.PHP--><?php get_header() ;?><!-- END -->

<div class="side"><?php if (have_posts()) ;?>
<?php $post = $posts[0]; // Thanks Kubrick for this code ;?>

<?php if (is_category()) { ;?>
<h3><?php _e('Archive for '); echo single_cat_title() ;?></h3>
<?php } elseif (is_day()) { ;?>
<h3><?php _e('Archive for '); the_time('F j, Y') ;?></h3>

<?php } elseif (is_month()) { ;?>
<h3><?php _e('Archive for '); the_time('F, Y') ;?></h3>

<?php } elseif (is_year()) { ;?>
<h2><?php _e('Archive for '); the_time('Y') ;?></h2>

<?php } elseif (is_author()) { ;?>
<h3><?php _e('Author Archive') ;?></h3>

<?php } elseif (is_search()) { ;?>
<h3><?php _e('Search Results') ;?></h3>
<?php } ;?>
<?php while (have_posts()): the_post() ;?>

<!--TITLE TAG-->
<h1><?php the_title() ;?></h1>
<!--END-->


<!--TIME DATE CATEGORY WORDS-->
<h2><?php the_time('F jS, Y'); ;?> by <?php the_author(); ;?>  &nbsp;  <?php comments_popup_link(__('0 Comments'), __('1 Comment'), __('% Comments'), 'commentslink', __('sorry, Comments off for this post.')) ;?> &nbsp;  <BR>
Filed Under: <?php the_category(', ') ;?> &nbsp;
</h2>
<!--END-->

<?php if (is_search()) { ;?>
<?php the_excerpt() ;?>
<?php } else { ;?>
<?php the_content(__('Read more &#187;'));?>


<!--COMMENTS TAG-->

<!--END-->
<br /> <br />

<?php comments_template(); // Get wp-comments.php template ;?>

<?php } ;?>

<!--
<?php trackback_rdf() ;?>
-->

<?php endwhile ;?>
<?php posts_nav_link('', __(''), __('&laquo; Previous entries')) ;?>
<?php posts_nav_link('  ', __(''), __('')) ;?>
<?php posts_nav_link('', __('Next entries &raquo;'), __('')) ;?>

<?php else: ?>
<h3><?php _e('Not Found'); ?></h3>
<p><?php _e('Sorry, but no posts matched your criteria.'); ?></p>
<?php endif; ?>
</div>

<!--THIS INCLUDES FOOTER.PHP-->
<?php get_footer(); ?><!-- END -->

why are you opening the php statement and closing it so many times. just echo the html within the php, it so much easier to see whats wrong because its easier to read.

Line 3 should be: <?php if (have_posts()) :?>

What's get_header ? It's not a PHP function, and you've not defined it in the code you've posted, so PHP doesn't know what you're trying to do. If you want to include 'header.php' in your file, use include , require , include_once or require_once . include simply inserts the contents of another file into the script. require does the same thing, but it also prints an error and kills the script if it can't find the file. The '_once' versions also make sure the file is only included once in the script. So if you want to use require , you would write require 'header.php'; .

You'll probably get another error when you get to the get_footer(); call at the bottom of the script; just do the same thing as above, replacing 'footer.php' for 'header.php'.

where are all of these functions you have coming from? get_header(), have_posts(), is_year(), ect.. your problem might be in them.
i will rewrite your code to help and see if i can find any errors. plz post the functions so we can look at them.

where are all of these functions you have coming from? get_header(), have_posts(), is_year(), ect.. your problem might be in them.
i will rewrite your code to help and see if i can find any errors. plz post the functions so we can look at them.

thanks soo soo much if you do that that would be so kind

and thanks for the help eveyone i really do suck sometimes lol

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.