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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:49:46+00:00 2026-05-20T10:49:46+00:00

I have seen many tutorials, but they’re so confusing, and to do what I

  • 0

I have seen many tutorials, but they’re so confusing, and to do what I want to do, I just don’t get how to use existing stuff from those tutorials and make them work they way I want them to.

I have a very simple form, containing a textbox, label and a submit button. When the user enters something into the form, then clicks submit, I would like to use php and ajax (with jquery) to insert the result of the form into a mysql database.

Can someone please show me how this can be achieved? Just something very basic is all i’m after to get me started. Any help is appreciated.

Thank you

  • 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-20T10:49:47+00:00Added an answer on May 20, 2026 at 10:49 am

    Hi here is just a quick example of how one might do it:

    The HTML:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
        <head>
            <title>Quick JQuery Ajax Request</title>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    
            <!-- include the jquery lib -->
            <script type="text/javascript" src="jquery.js"></script>
            <script type="text/javascript">
                var ajaxSubmit = function(formEl) {
                    // fetch where we want to submit the form to
                    var url = $(formEl).attr('action');
    
                    // fetch the data for the form
                    var data = $(formEl).serializeArray();
    
                    // setup the ajax request
                    $.ajax({
                        url: url,
                        data: data,
                        dataType: 'json',
                        success: function() {
                            if(rsp.success) {
                                alert('form has been posted successfully');
                            }
                        }
                    });
    
                    // return false so the form does not actually
                    // submit to the page
                    return false;
                }
            </script>
    
        </head>
        <body>
    
            <form method="post" action="process.php"
                  onSubmit="return ajaxSubmit(this);">
                Value: <input type="text" name="my_value" />
                <input type="submit" name="form_submit" value="Go" />
            </form>
    
        </body>
    </html>
    

    The process.php script:

    <?php
    
    function post($key) {
        if (isset($_POST[$key]))
            return $_POST[$key];
        return false;
    }
    
    // setup the database connect
    $cxn = mysql_connect('localhost', 'username_goes_here', 'password_goes_here');
    if (!$cxn)
        exit;
    mysql_select_db('your_database_name', $cxn);
    
    // check if we can get hold of the form field
    if (!post('my_value'))
        exit;
    
    // let make sure we escape the data
    $val = mysql_real_escape_string(post('my_value'), $cxn);
    
    // lets setup our insert query
    $sql = sprintf("INSERT INTO %s (column_name_goes_here) VALUES '%s';",
                    'table_name_goes_here',
                    $val
    );
    
    // lets run our query
    $result = mysql_query($sql, $cxn);
    
    // setup our response "object"
    $resp = new stdClass();
    $resp->success = false;
    if($result) {
        $resp->success = true;
    }
    
    print json_encode($resp);
    ?>
    

    Please note that none of this has been tested. I hope it helps you thou.

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

Sidebar

Related Questions

I have seen simple example Ajax source codes in many online tutorials. What I
I have seen many tutorials on how to compress a single file in c#.
I have seen many tutorials where the hibernate is implemented using annotations (basically hibernate
I have seen many others with similar problems but I cannot find the flaw
I have seen many somewhat similar questions, but nothing quite what I'm looking for.
I have seen many programs consisting of structures like the one below typedef struct
I have seen many examples, with many 'no, you missed something' comments. What is
I have seen many apps that take instrument classes and take -javaagent as a
I have seen this problem arise in many different circumstances and would like to
Many times I have seen Visual Studio solutions which have multiple projects that share

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.