简体   繁体   中英

Inserting an array to mysql query

I am trying to insert a form data into mysql database using php and jquery ajax But i can't find a way to use that array and use in sql query

HOW CAN I INSERT THIS OUTPUT INTO MYSQL QUERY

This is my ajax code

var i = JSON.stringify(e.serializeObject(), null, 2);

$.ajax({
            type: "POST",
            url: "insert.php",
            data: "form="+ i, 
            cache: false,
            success: function(html){
            console.log(html);

            }
            });

insert.php

<?php
$data = $_POST['form'];
print_r($data);

Output

{
  "user_edit_uname_control": "demo",
  "user_edit_position_control": "Web Developer",
  "user_edit_address_control": "123 xxx xxx",
  "user_edit_city_control": "city",
  "user_edit_phone": "00042542424",
  "user_edit_dob_control": "00.00.000",
  "val_radio_gender": "m",
  "user_edit_personal_info_control": "s ssfsf s   s sf sf",
  "user_g_cu": "",
  "user_g_per": "",
  "user_g_yer": "",
  "user_g_degre": "",
  "Schol_twele_per": "",
  "Schol_twele_yer": "",
  "Schol_twele_board": "",
  "Schol_ten_per": "",
  "Schol_ten_yer": "",
  "Schol_ten_board": "",
  "checkbox_public_view": "on"
}

if you want to store the array in one cell in the database you can use serialize() to convert the array to a string and store it in DB

http://php.net/manual/en/function.serialize.php

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM