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 7797779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:47:44+00:00 2026-06-01T23:47:44+00:00

I have a simple form with some PHP code to post to a database

  • 0

I have a simple form with some PHP code to post to a database some simple information.

The connection to the database is just fine because it display items I have manually entered exactly how I want it to; however. I cannot get it to post from the form into the database. I have tinkered with a lot of code with no luck. Anyone see anything I’m missing? Here is the code:

<center>
<form action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>" method="POST">

    <strong><h2><br><br>Enter in my guestbook!</h2></strong><br>
    <h3>Nickname:</h3><input type="text" name="guestbook_name" maxlength="25"><br>
    <h3>Write About Your Day:</h3><textarea name="guesbook_message" rows="6" cols="60"       maxlength="255"></textarea><br>
    <input type ="submit" value="POST">

</form>

<br>
<hr>
<br>

<?php

    if (mysql_connect('localhost', 'root', 'root') && mysql_select_db('mydb')) {

    //echo 'Connected to the database!';

    $time = gmdate("l dS \of F Y h:i:s A");
    $errors = array();

    if (isset($_POST['guestbook_name'], $_POST['guestbook_message'])) {

        echo 'Set data!';

        $guestbook_name = mysql_real_escape_string(htmlentities(     $_POST['guestbook_name'])); 
        $guestbook_message = mysql_real_escape_string(htmlentities(     $_POST['guestbook_message'])); 

        if (empty($guestbook_name) || empty($guestbook_message)) {
        $errors[] = 'All fields are required.';
        }

        if (strlen($guestbook_name)>25 || strlen($guestbook_message)>250){
        $errors[] = 'One or more fields exceeded the character limit!'; 
        }

        if (empty($erros)) {
            $insert = "INSERT INTO guestbook VALUES     ('','$time','$guestbook_name','$guestbook_message')";
            if (mysql_query($insert)){
                 header ('Location: '.$_SERVER['PHP_SELF']);
            } else {
                $errors[] = 'Something went wrong. Try again.';
            }

        } else {
            foreach($errors as $error) {
                echo'<p><strong>'.$error.'</strong></p>'; 
            }

        }

    }

    // display entries 
    $entries = mysql_query("SELECT timestamp, name, message FROM guestbook ORDER BY timestamp DESC");

    if (mysql_num_rows($entries)==0){
        echo 'No entries, yet.';
        } else { 
            //echo 'Entries found.'; 

            while ($entries_row = mysql_fetch_assoc($entries)){
                $entries_timestamp = $entries_row['timestamp'];
                $entries_name = $entries_row['name'];
                $entries_message = $entries_row['message'];
                echo '<p><strong>Posted by '.$entries_name.' on     '.$entries_timestamp.'</strong>:<br><br>'.$entries_message.'</p><br><br>';

            }
        }

} else {
    echo 'Could not connect at this time.';
} 


?>

</center>

My main issue is the submitting the database, any help would be great, thanks!

Kyle B.

  • 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-06-01T23:47:47+00:00Added an answer on June 1, 2026 at 11:47 pm

    We will need to see your database table structure vs. your insert sql statement to see if you are inserting properly.

    Most likely cause of failed insert is not setting a field value which is set to NOT NULL, (either by not inserting a value, or having an empty/mistyped variable).

    But more common problems are:

    wrong table or field names
    not having the enough privelages on your database user account
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple html form and some php that input the POST variables
I have simple form. <form target=_blank action=somescript.php method=Post id=simpleForm> <input type=hidden name=url value=http://...> <input
I have a PHP form that needs some very simple validation on submit. I'd
I have a simple form with some plain html input like bellow using ASP.NET
Have a simple form (only extract fields here) but for some reason the JQserilization
There are some HTML based games (ie bootleggers.us) that have a simple login form
I have a very simple XAML form, that has one namespace definition. For some
I have a simple form that looks like so <% remote_form_for post, :url =>
I have a simple form like this: <form name=serachForm method=post action=/home/search> <input type=text name=searchText
Let's say that I have a file (file1.php) with a simple form with the

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.