Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7054893
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:40:56+00:00 2026-05-28T03:40:56+00:00

I’m fairly new to PHP and designing a small blog. I’m trying to submit

  • 0

I’m fairly new to PHP and designing a small blog. I’m trying to submit a form to create a new post but it isn’t working and I can’t figure out why. I’ve compared it to my working code for the register form and it seems the same. I’m not getting any errors, it’s just reloading the page and not posting to the database.

View – v_newpost.php

    <article>
    <?php
    if (!isset ($_SESSION['username']))
    {
    ?>
    <span class="alert">Please login to create a post.</span>
    <?php
    }

    else 
    {
    ?>
    <form class="newpost" action="" method="post">
    <fieldset>
    <legend>Submit a new post</legend>
    <?php if ($error['alert'] != '') { echo "<span class='alert'>".$error['alert']."</span>";} ?>
    <ul>
    <li>
    <label for="title">Title:</label>
    <input type="text" name="title" value="<?php echo $input['title']; ?>" required autofocus>
    </li>
    <li>
    <label for="content">Content:</label>
    <textarea id="content" name="content" rows=6 value="<?php echo $input['content']; ?>"></textarea>
    </li>
    </ul>
    </fieldset>
    <fieldset>
    <button type="submit" class=postbutton>Publish</button>
    </fieldset>
    </form>
    </div>
    <?php
    }
    ?>
</article>

newpost.php

    <?php
    require_once 'includes/connection.php';

$error['alert'] = '';
$input['title'] = '';
$input['content'] = '';

if (isset($_POST['submit']))
{
    if ($_POST['title'] == '' || $_POST['content'] == '')
    {
        $error['alert'] = 'Please give your post a title and content.';

        $input['title'] = $_POST['title'];
        $input['content'] = $_POST['content'];

        include_once('v_newpost.php');
    }
    else
    {
        $input['title'] = htmlentities($_POST['title'], ENT_QUOTES);
        $input['content'] = htmlentities($_POST['content'], ENT_QUOTES);

        if ($stmt = $mysqli->prepare("INSERT INTO posts (title, content) VALUES (?,?)"))
        {
            $stmt->bind_param("ss", $input['title'], $input['content']);
            $stmt->execute();
            $stmt->close();

            $error['alert'] = '';
            $input['title'] = '';
            $input['content'] = '';

            header('Location: index.php');
        }
        else
        {
            $error['alert'] = 'Failed to create post';
        }
    }

}
else
{
    include_once('v_newpost.php');
}


?>

I’m sure it’s probably something stupid, but I’ve looked over it so many times and can’t understand why it isn’t working…

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:40:57+00:00Added an answer on May 28, 2026 at 3:40 am

    The following will never be true since you have no form element with name="submit".

    if (isset($_POST['submit']))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
I want to count how many characters a certain string has in PHP, but
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.