Issue with ForEach on Post Add Page for Blog

Hey everyone,
I am beginning with PHP and slowly trying to fumble my way through this. I am working on building just a basic blog function, everything I have seems to be fine except for the page used to add posts. There seems to be an issue with my foreach on line 38 but for the life of me I can figure out. Can any one help?

[php]

<?php if(empty($_POST)) { $status = 'To add a new post, fill out the form below. Click the Add Post button once.'; } else { $title = $_POST['title'] ; $summary = $_POST['summary'] ; $content = $_POST['content'] ; $error_list = array(); if(empty($title)) { $error_list[] = 'You did not supply a Title'; } if(empty($summary)) { $error_list[] = 'You did not supply a Summary'; } if(empty($content)) { $error_list[] = 'You did not supply any Content'; } if(empty($error_list)) { mysql_connect('test','test','test') or die ("could not connect to mysql"); mysql_select_db('test') or die ("no database"); $sql = "INSERT INTO blog_posts "; $sql = "SET title='$title', date_posted=NOW(), summary= '$summary', content='$content' "; if(mysql_query($sql)) { header('Location: index.php'); } } else { $status = '
    ' foreach($error_list as $error_message) { $status .= "
  • $error_list
  • " ; $status .= '
' ; } } ?>

[/php]

Hi there, if you haven’t figured it out already, I believe I’ve sorted you out below (you’ll kick yourself!)

End of your script:

if(mysql_query($sql)) { header('Location: index.php'); } } else { $status = '
    '

    foreach($error_list as $error_message) {
    $status .= “

  • $error_list
  • ” ;

    $status .= ‘

’ ;

}
}
?>

new end of your script:
[php]
if(mysql_query($sql)) {
header(‘Location: index.php’);
}
}
else {
$status = ‘

    ’;

    foreach($error_list as $error_message) {
    $status .= “

  • $error_list
  • ” ;

    $status .= ‘

’ ;

}
}
?>
[/php]

You were missing a semi-colon on the line above your foreach! :-/.

Sponsor our Newsletter | Privacy Policy | Terms of Service