简体   繁体   English

将数组插入到 mysql 查询

[英]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我正在尝试使用 php 和 jquery ajax 将表单数据插入 mysql 数据库但我找不到使用该数组并在 sql 查询中使用的方法

HOW CAN I INSERT THIS OUTPUT INTO MYSQL QUERY我如何将此输出插入到 MYSQL 查询中

This is my ajax code这是我的ajax代码

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

<?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如果要将数组存储在数据库的一个单元格中,可以使用serialize()将数组转换为字符串并将其存储在 DB 中

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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