My blog was posting originally, however, as you work on things, things break. Now I can't for the life of me figure out why nothing is happening! The categories post to the database just fine, but my posts refuse to. Heres what I have

```
<?php
include_once('header.php');

if(isset($_POST['title'], $_POST['contents'], $_POST['category'])){
    $errors = array();
    if(!empty(trim($_POST['title']))){
        $title = trim($_POST['title']);
    }else{
        $errors[] = 'Please enter title';
    }
    if(!empty(trim($_POST['contents']))){
        $contents = trim($_POST['contents']);
    }else{
        $errors[] = 'You need to supply the content';
    }
    if(!category_id_exists($_POST['category'])){
        $errors[] = 'That category does not exist.';
    }
    if(strlen(trim($_POST['title']))>255){
        $errors[] = 'The title cannot be longer than 255 characters.'; 
    }

    if(empty($errors)){
        add_post($title, $contents, $_POST['category']);
        $id = mysqli_insert_id($mysql_connect);
        $header_string = 'Location: index.php?id='.$id;
        header($header_string);
        die();
    }

} 
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <style>
        label { display: block;}
    </style>

    <title>Add a Post</title>
</head>
<body>
    <h1> Add a Post </h1>
    <?php 
    if(isset($errors) && !empty($errors)){
        echo '<ul><li>', implode('</li><li>', $errors), '</li></ul>';
    }
    ?>

    <form action="" method="post">
        <div>
            <label for="title"> Title </label>
            <input type="text" name="title" value="<?php if(isset($_POST['title'])) echo $_POST['title']; ?>">
        </div>
        <div>
            <label for="contents"> Contents </label>
            <textarea name="contents" rows="15" cols="50"><?php if(isset($_POST['contents'])) echo $_POST['contents']; ?></textarea>
        </div>
        <div>
            <label for="category"> Category </label>
            <select name="category">
                <?php
                foreach(get_categories() as $category){
                    ?>
                    <option value="<?php echo $category['id']; ?>"><?php echo $category['name']; ?> </option>
                    <?php
                }
                ?>
            </select>
        </div>
        <div>
            <input type="submit" value="Add Post">
        </div>
    </form>
</body>
</html>

```

Inside the header.php file, I call an init.php connect to db file which also in itself, include\_once all the functions for my blog (blog.php). The function that specifically is necessary is as follows...

```
function add_post($title, $contents, $category){
    global $mysql_connect;

    $title = mysqli_real_escape_string($mysql_connect, $title);
    $contents = mysqli_real_escape_string($mysql_connect, $contents);
    $category = (int)$category;

    $result = mysqli_query($mysql_connect, "INSERT INTO posts SET cat_id = '$category', title = '$title', contents = '$contents', date_posted = NOW()");
}

```

I figured a fresh set of eyes could be really valuable for me right now. When I click add post, it brings me to a page titled <http://localhost/blog/index.php?id=0>. Therefore it's not only not registering to the database, but it's not using the categories either. 

I hope I explained this okay! I've been at this for a week now.

Edit: I ran error checks and nothing posts, so I am not sure what's going on!

Edit2: Selecting categories I add, also work and list the way I want them to. Its just something happening when I go to click add post, nothing occurs. I'm assuming its in this area 

```
if(empty($errors)){
    add_post($title, $contents, $_POST['category']);
    $id = mysqli_insert_id($mysql_connect);
    $header_string = 'Location: index.php?id='.$id;
    header($header_string);
    die();
}

```