Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

This question already has an answer here:

I have a error:

Parse error: syntax error, unexpected '<' in /home/dgsite81/public_html/dgprint/wp-content/themes/dgprint/taxonomy-product_category.php on line 197

CODE PHP:

<?php 
    $queried_object = get_queried_object(); 
    $cat_content = get_field('category_content', $queried_object);
    $imagine2= get_field('imagine2',$queried_object);                      
    $imagine3= get_field('imagine3',$queried_object);                 
    $imagine4= get_field('imagine4',$queried_object);
    $imagine5= get_field('imagine5',$queried_object);

           $fields = array("cat_content","imagine2","imagine3","imagine4","imagine5");
             <ul>  //here is the line with error 
                <?php foreach($fiedls as $value) { ?>
                    <li><?php echo $value; ?></li>
                <?php } ?>
             </ul>
?>

How can I fix this error? I did not realize what I should add parentheses and where exactly.

share|improve this question

marked as duplicate by Rizier123 php Jun 25 '15 at 13:19

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
You cant just write HTML into PHP Code... After the $fields line add ?> and after the </ul> add <?php again. – boast Jun 25 '15 at 13:13
    
add ?> before the <ul> – Paul Dixon Jun 25 '15 at 13:13
up vote 0 down vote accepted

You are missing closing tag for php, so php automatically tries to parse it.

Correct code:

$fields = array("cat_content","imagine2","imagine3","imagine4","imagine5"); ?>
<ul>  //here is the line with error
share|improve this answer

You're mixing PHP and HTML. You need to enclose your PHP code in <?php ?> brackets...

$fields = array("cat_content","imagine2","imagine3","imagine4","imagine5");
?> <!-- This tells the PHP parser to stop parsing as PHP code -->
  <ul>
share|improve this answer

You're using HTML inside a php tag, you can either do echo "<ul>" or close PHP and then do ul like this:

<?php 
                    $queried_object = get_queried_object(); 
                    $cat_content = get_field('category_content', $queried_object);
                    $imagine2= get_field('imagine2',$queried_object);                      
                    $imagine3= get_field('imagine3',$queried_object);                 
                    $imagine4= get_field('imagine4',$queried_object);
                    $imagine5= get_field('imagine5',$queried_object);

                           $fields = array("cat_content","imagine2","imagine3","imagine4","imagine5"); ?> <------- this thing here
                             <ul>  //here is the line with error 
                                <?php foreach($fiedls as $value) { ?> 
                                    <li><?php echo $value; ?></li>
                                <?php } ?>
                             </ul>

                    ?>
share|improve this answer

you just need to close the php script it before that line

 <?php 
                    $queried_object = get_queried_object(); 
                    $cat_content = get_field('category_content', $queried_object);
                    $imagine2= get_field('imagine2',$queried_object);                      
                    $imagine3= get_field('imagine3',$queried_object);                 
                    $imagine4= get_field('imagine4',$queried_object);
                    $imagine5= get_field('imagine5',$queried_object);

                           $fields = array("cat_content","imagine2","imagine3","imagine4","imagine5");
                             ?>
                             <ul>
                                <?php foreach($fiedls as $value) { ?>
                                    <li><?php echo $value; ?></li>
                                <?php } ?>
                             </ul> 


?>
share|improve this answer

Yes because you used HTML tags directly in a PHP code. Try this:

<?php
    $queried_object = get_queried_object();
    $cat_content = get_field('category_content', $queried_object);
    $imagine2= get_field('imagine2',$queried_object);
    $imagine3= get_field('imagine3',$queried_object);
    $imagine4= get_field('imagine4',$queried_object);
    $imagine5= get_field('imagine5',$queried_object);

    $fields = array("cat_content","imagine2","imagine3","imagine4","imagine5");
?>
     <ul>
        <?php foreach($fiedls as $value) { ?>
            <li><?php echo $value; ?></li>
        <?php } ?>
     </ul>
share|improve this answer

this is basic syntax please document yourself better... try this:

 <?php
                    $queried_object = get_queried_object();
                    $cat_content = get_field('category_content', $queried_object);
                    $imagine2= get_field('imagine2',$queried_object);
                    $imagine3= get_field('imagine3',$queried_object);
                    $imagine4= get_field('imagine4',$queried_object);
                    $imagine5= get_field('imagine5',$queried_object);

                           $fields = array("cat_content","imagine2","imagine3","imagine4","imagine5");
                            echo '
                             <ul>';
                                foreach($fiedls as $value){
                                    echo '
                                    <li>'.$value.'</li>';
                                }
                            echo '
                            </ul>';

?>
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.