I want to store my array into my database using jQuery. Here is my code i'm using serialize(); function. Its storing correctly but when i unserialize(); nothing happening. Please help here is my code.

            var skills = $('input[name="skills[]"]').serialize();
            $('#loading').css('display', 'block');
            var queryString = "skills=" + skills + "";
              url: 'save_skills.php',
              cache: false,
              contentType: "application/json; charset=utf-8",
              async: false,
              data: queryString,
              success: function(data){
                $('#loading').css('display', 'none');
                if('error' in data){
                }else if('success' in data){

<!-- Unserialize() code -->

$who = $_COOKIE['Email'];
$skills = @mysql_query("SELECT * FROM `skills` WHERE `who` = '$who'");
$skill_count = @mysql_num_rows($skills);
echo "<h1>Skill count : $skill_count</h1>";
while($sk = @mysql_fetch_array($skills)){
    $set_of_skills = "{$sk['set_of_skills']}";
    echo "<h1>Array skills : $set_of_skills</h1>";

this is printing nothing.

Recommended Answers

All 4 Replies

Member Avatar for diafol

this is printing nothing.

I assume that you get skill_count and the h1 echo? If not your problem is not the print_r but probably the SQL.

Member Avatar for diafol

Ok, the serialize/unserialize functions I don't think are compatible. The serialize() is a jQuery function, which produces a 'url-like' querystring.

Serializing with PHP creates a whole different beast, so I can't see how they'd work together. Serialize/Unserialize with the same language.

Sorry for late reply - leaving a comment doesn't flag the watched list that there's any change. Mind you I don't mind the rep! :)

Is there any way to store the array into the database using jQuery ?

Member Avatar for diafol

How do you need your data stored? url-type (jQuery serialize) or the more info-full php serialize?
You can't use jQuery to store to db without using ajax.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.