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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:27:48+00:00 2026-05-27T22:27:48+00:00

I’m having trouble working this out for inserting input values into database. I have

  • 0

I’m having trouble working this out for inserting input values into database.

I have something like this

$("form#profileName").submit(function(){
    var updateName = $(this).serialize();
    $.post("update.php",{updateName: updateName},function(data){
        alert(data);
    });
    return false;
});

In my PHP I have something like this

if(isset($_POST['updateName'])){
    $fname = $_POST['updateName']['f_name'];
    $mname = $_POST['updateName']['m_name'];
    $lname = $_POST['updateName']['l_name'];
    $altname = $_POST['updateName']['alt_nam'];

    echo $fname." ".$mname." ".$lname." ".$altname;

}

its echoing out “f f f f” for some reason,

am I doing this correctly?

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-27T22:27:49+00:00Added an answer on May 27, 2026 at 10:27 pm

    Here’s some documentation on .serialize()
    You’re basically serializing it twice.

    var updateName = $(this).serialize(); //f_name=somename&m_name=some
    $.ajax({
        ...
        data: {updateName: updateName} //{updateName: 'somename&m_name=some'}
        //which is translated into updateName=f_name%3dsomename%26m_name%3dsome
    });
    

    I’m going to take a wild guess and say that the reason it’s outputting “f f f f” is because the $_POST['updateName'] is now a single string. Each individual character in PHP is accessed like this $string[n]. I suppose it’s interpreting blank as 0, and gives you the first character, which is in fact “f”.

    Here’s how it should look like:

    $("form#profileName").submit(function(){
        var updateName = $(this).serialize();
        $.post("update.php",updateName,function(data){
            alert(data);
        });
        return false;
    });
    

    or, in my opinion, the beautiful and clean way,

    $("form#profileName").submit(function(){
        var updateName = $(this).serialize();
        $.ajax({
            url: "update.php",
            type: "POST",
            data: updateName,
            success: function(msg){
                alert(data);
            }
        });
        return false;
    });
    

    And the PHP $_POST variable will now have several values, which are accessed like this:

    $_POST['f_name']
    $_POST['m_name']
    ...
    

    Also note that in the PHP script, you might have to use urldecode() or rawurldecode() on your variables, depending on how you send the data in the JS (encodeURI() or encodeURIComponent()).

    In this case, serialize() has it’s own internal encodeURI(), so there is no need for it, but the PHP might need to decode it.
    If you’re still having problems after you’ve fixed the 2xSerialize, just change the PHP script to decode the encoded data:

    $fname = urldecode($_POST['f_name']);
    $mname = urldecode($_POST['m_name']);
    ...
    

    Sidenote:
    If you’ve got an ID attr on the form, why not use: $("#profileName").submit(...)?
    Makes more sense if you ask me.

    Debugging
    Depending on what browser you’re using, you can check what XHR is sending to/recieving from the server. In Firefox you can use the plugin called Firebug (XHR panel is under Net->XHR)
    Mike also mentioned debugging in Chrome:

    Developer tools in chrome -> Network -> XHR at the bottom


    Final solution

    The solution should now look something like this:

    Javascript:

    $("form#profileName").submit(function(){
        var updateName = $(this).serialize();
        $.ajax({
            url: "update.php",
            type: "POST",
            data: updateName,
            success: function(msg){
                alert(data);
            }
        });
        return false;
    });
    

    PHP script “update.php”:

    if(isset($_POST)){
        $fname = $_POST['f_name'];    //urldecode($_POST['f_name']);
        $mname = $_POST['m_name'];    //urldecode($_POST['m_name']);
        $lname = $_POST['l_name'];    //urldecode($_POST['l_name']);
        $altname = $_POST['alt_nam']; //urldecode($_POST['alt_nam']);
    
        echo "$fname $mname $lname $altname";
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a text area in my form which accepts all possible characters from
I'm having trouble keeping the paragraph square between the quote marks. In firefox 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.