-2

I've been struggling to find the error in my code. Any help would be appreciated.

<?php 
   if(isset($_SESSION["pkg_error"]));
?>
<div class="error_msg_cont">
<?php 
     foreach($_SESSION["pkg_error"] as $error)
     {
         echo $error. "<br>"
     } 
 ?>
 </div>
<?php 
     if(isset($_SESSION["msg"]))
     {
          echo '<div class="error_msg_cont">'. $_SESSION["msg"] .'<div>'
     }
?>

Edit, I updated the code but am still getting an error. Did I update this wrong? Been trying to fix this for over 3 hours. This is the error I'm getting: Parse error: syntax error, unexpected T_STRING, expecting ',' or ';'

<?php 
    if(isset($_SESSION["pkg_error"])) 
?>
<div class="error_msg_cont">
<?php 
    foreach($_SESSION["pkg_error"] as $error)
    { 
        echo $error. "<br>"; 
    } 
?>
</div>
<?php 
    if(isset($_SESSION["msg"]))
    {
        echo "('<div class="error_msg_cont">'. $_SESSION["msg"] .'<div>')"; 
    } 
?>
programmingnewb
  • 129
  • 2
  • 9
  • `echo '
    '. $_SESSION["msg"] .'
    '` needs a `;` at the end of the line; as does `echo $error. "
    "`
    – Mark Baker Jul 24 '13 at 23:27
  • `;` after `if` condition? – elclanrs Jul 24 '13 at 23:27
  • why does the `if` in the first line have a `semi-colon` in the end. – Hakim Jul 24 '13 at 23:27
  • I tried to use the advice in the other question and responded with the details of what happened. Nobody responded back to that one, so I was trying again, hoping for new answers. – programmingnewb Jul 24 '13 at 23:47
  • I changed the code to: – programmingnewb Jul 24 '13 at 23:52
  • There's another easy-to-spot error then. Errors always include line numbers. Consider reading or googling the message. It's unclear why and how you introduced another syntax problem after trashing the code layout after such a short amount of time. Explain. – mario Jul 25 '13 at 00:06
  • I've found that the line numbers aren't always correct. Trust me, I've been trying to fix this for a long time. Tried every combination of semicolons I could think of. At this point I've just made it worse and will likely have to hire someone to fix it. Was just hoping someone saw an obvious problem and could help. I'm not sure how I trashed the code layout, not even sure what that means. I just copy and pasted the code from Kompozer. – programmingnewb Jul 25 '13 at 00:10
  • I just went and formatted the code better. That is not my duplicate... – programmingnewb Jul 25 '13 at 00:17
  • Consider actually reading. It's not your repost, but one of a billion duplicate questions. Else play spot the difference and syntax highlighting on your own code. – mario Jul 25 '13 at 00:23
  • Does it make you feel good about yourself to be condescending? I've looked at many of the similar questions on here and couldn't figure it out. Like I said, been trying to fix this now for 4 hours. The suggestions made here didn't solve the problem when I implemented them. Just trying to fix this without spending the next week on a syntax problem. I'm a complete newb and was just trying this out. – programmingnewb Jul 25 '13 at 00:31

2 Answers2

0

PHP statements should be terminated with a semi-colon:

echo $error. "<br>";

This occurs further down as well:

echo '<div class="error_msg_cont">'. $_SESSION["msg"] .'<div>';

You can get away with this sometimes, but for an echo statement, it doesn't know where the echo is supposed to finish.

Also note that your opening if statement is finished immediately by the semi-colon at the end of that line.

Added The quotes are all out of whack in the last echo statement (of the revised code), corrected here:

    echo "<div class='error_msg_cont'>" . $_SESSION["msg"] . "<div>"; 

But the first if-statement is still ineffective. It should be followed by curly brackets, enclosing the statements that need to be executed if the if-condition is true.

Andy G
  • 19,232
  • 5
  • 47
  • 69
  • Thanks for your help. I added that in, and am still getting an error. Not sure where to turn now. – programmingnewb Jul 25 '13 at 00:44
  • I've added to my answer. When you post an error message please include the line number that the message includes, and tell us which line this refers to in your posted code. – Andy G Jul 25 '13 at 01:21
0
<?php if(isset($_SESSION["pkg_error"]))?>
  <div class="error_msg_cont"><?php foreach($_SESSION["pkg_error"] as $error)
{
    echo $error. "<br>";
} ?></div>
<?php if(isset($_SESSION["msg"]))
{
     echo '<div class="error_msg_cont">'. $_SESSION["msg"] .'<div>';
}
?>

you are missing semi-colon's after your echo's. also and unwanted semi-colon after your first if statement

srakl
  • 2,565
  • 2
  • 21
  • 32