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

  • Home
  • SEARCH
  • 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 235197
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:14:48+00:00 2026-05-11T20:14:48+00:00

When a user inserts data into a form and then submits it, it goes

  • 0

When a user inserts data into a form and then submits it, it goes to my php script and inserts the data. The script will return a value letting the user know if the data was inserted or not. Since I am using JQuery, I have no idea how to do this. Can someone please point me in the right direction? All I’m after here is a nice, neat little 200px by 25px container that will fade in and the user MUST click it to acknowledge it.

Now that I think about it, since users are not the brightest lights in the harbor, it would be really cool if I could not only show then this css box letting them know if the insert was successful but also show them the customer that was inserted in case they forgot where they left off.

Thanks.

  • 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-11T20:14:48+00:00Added an answer on May 11, 2026 at 8:14 pm

    I’m not going to mark this as a duplicate, but you are essentially asking the best way to show notifications using jQuery. And that has been asked before. In a nutshell, in your basic setup all you need to do is show a div and fade it in, but there are a lot of plugins out there that handle more situations.

    As far as showing them the customer that was inserted or whatever, all you have to do is return a JSON response from the server and handle it with the success callback of your AJAX request. You will have access to the data passed back from the server then.

    To explain a little further: What you seem to be asking to do is how to send a request to a server using Ajax, get a notification that everything went as expected, and then show a notification in the webpage depending on what happened. If that is correct, I’m going to move on with these assumptions.

    Let’s put together a simple form to add a new customer to a fictional website. It might look like this:

    <form action='add_customer.php' method='POST' id='add_customer_form'>
        First Name: <input type='text' name='first_name'><br>
        Last Name: <input type='text' name='last_name'><br>
        Email: <input type='text' name='email'><br>
        <input type='submit' value='Add Customer'>
    </form>
    

    Now, our naive, insecure PHP code to handle this form submission (through AJAX) might look something like this. I say naive and insecure because you would do more data validation (as you never trust anything coming from the client) and would certainly need to clean the data to prevent SQL injections. This is an example, however, so it might look like this:

    $first_name = $_POST['first_name'];
    $last_name = $_POST['last_name'];
    $email = $_POST['email'];
    if(mysql_query("
        INSERT INTO customers
        (first_name, last_name, email)
        VALUES 
        ('$first_name','$last_name','$email')
       ")) {
        $success = 1;
        $message = 'Customer ' . $first_name . ' successfully added!';
    } else {
        $success = 0;
        $message = 'Something went wrong while adding the customer!';
    }
    print json_encode(array('success' => $success, 'message' => $message));
    

    We might then handle the sending of this form and the receiving of data from the server, using jQuery, with code that looks a little something like this:

    $(function() {
        $('#add_customer_form').submit(function() { // handle form submit
            var data = $(this).serialize(); // get form's data
            var url = $(this).attr('action'); // get form's action
            var method = $(this).attr('method'); // get form's method
            $.ajax({
                url: url, // where is this being sent to?
                type: method, // we're performing a POST
                data: data, // we're sending the form data
                dataType: 'json', // what will the server send back?
                success: function(data) { // the request succeeded, now what?
                    // here data is a JSON object we received from the server
                    // data.success will be 0 if something went wrong
                    // and 1 if everything went well. data.message will have
                    // the message we want to display to the user
                    // at this point you would use one of the techniques I linked
                    // to in order to display a fancy notification
    
                    // the line below will dynamically create a new div element,
                    // give it an ID of "message" (presumably for CSS purposes)
                    // and insert the message returned by the server inside of it
                    var $div = $('<div>').attr('id', 'message').html(data.message);
    
                    if(data.success == 0) {
                        $div.addClass('error'); // to personalize the type of error
                    } else {
                        $div.addClass('success'); // to personalize the type of error
                    }
                    $('body').append($div); // add the div to the document
                }
            });
            return false; // prevent non-ajax form submission.
        });
    });
    

    I haven’t tested any of this code but the idea is there. You return a format, JSON, from the server, with data, and handle the success callback jQuery fires when the request is complete, and add an element to your document you can style however you want (and show with things like fadeIn() if you want) with a message describing what happened. You might also need to catch the error callback (which fires if your server doesn’t respond for whatever reason) and firing off another alert in that situation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 313k
  • Answers 313k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer "C" is the default currency format string, which will always… May 13, 2026 at 10:49 pm
  • Editorial Team
    Editorial Team added an answer I never use custom collection types, mainly because I'm lazy.… May 13, 2026 at 10:49 pm
  • Editorial Team
    Editorial Team added an answer Ok, after some time of trying to construct a fitting… May 13, 2026 at 10:49 pm

Related Questions

A lot of lead up: I have a simple ASP .NET 3.5 data entry
I am developing a personal PHP/MySQL app, and I came across this particular scenario
I am using CF8 and MySQL 5. I have a form with several date
I have a VB6 application which works with datetime values in SQL Server (which

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.