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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:14:00+00:00 2026-06-11T08:14:00+00:00

I am trying to insert data from my select box option s into my

  • 0

I am trying to insert data from my select box options into my database table. My database table fields are id_country and country_name.

The database field id_country is populated from the select option value and the country_name is from the corresponding option text.
the code is like this..

<select id="id_country" name="id_country">
  <option value="17" >USA</option>
  <option value="16" >Canada</option>
  <option value="7" >France</option>
</select>

<script>
$(document).ready(function(){
    var data=new Array();
        $('#id_country').find('option').each(function() {
            var id=$(this).val();
            data[id]=$(this).text();

        });     

    $('#btn_insert').click(function(){
        $.ajax({
            type: "POST",
            url: "ajax.php",
            data: data,
            success: function(response){
                alert(response);
            }
        });                                     
    });

});
</script>   

The server side script:

<?php
     //echo $_POST['data'];
    $arr=$_POST['data'];
    foreach($arr as $key => $value){
       $sql="INSERT INTO Country($key,$value)";
       $query=mysql_query($sql);
       if(mysql_num_rows($query)>0){
          echo "success";
       }
     }
?>

I can’t get $_post['data'] value. How do I get the Javascript Array in the PHP script?

  • 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-11T08:14:02+00:00Added an answer on June 11, 2026 at 8:14 am

    Try as below:

    First serialize your array and then pass to jquery ajax function.

    data.serializeArray();
    

    In PHP Script, at the beginning of file,

    $arr = json_decode($_POST['data'], true);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to select data from two tables and insert it into another
I am trying to insert data from a database into a textarea. I can't
I am trying to insert data from one of my existing table into another
i am trying to insert data from excel sheet into database in java. for
I am trying to insert into Table A, unique data from Table B that
When trying to INSERT data into a database table, I've been getting the following
I'm trying to insert some data from a XML document into a variable table.
I've been trying to insert data from one row in a temporary table into
I am trying to insert some data from one table into another but I
I am trying to insert data from table a to table b (both are

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.