How to get JSON code into MYSQL database?
Posted
by
the_boy_za
on Stack Overflow
See other posts from Stack Overflow
or by the_boy_za
Published on 2012-03-30T10:55:04Z
Indexed on
2012/03/30
11:29 UTC
Read the original article
Hit count: 327
I've created this form with a jQuery autocomplete function. The selected brand from the autocomplete list needs to get sent to a PHP file using $.ajax function. My code doesn't seem to work but i can't find the error. I don't know why the data isn't getting inserted into MYSQL database. Here is my code:
JQUERY:
$(document).ready(function() {
$("#autocomplete").autocomplete({
minLength: 2
});
$("#autocomplete").autocomplete({
source: ["Adidas", "Airforce", "Alpha Industries", "Asics", "Bikkemberg", "Birkenstock", "Bjorn Borg", "Brunotti", "Calvin Klein", "Cars Jeans", "Chanel", "Chasin", "Diesel", "Dior", "DKNY", "Dolce & Gabbana"]
});
$("#add-brand").click(function() {
var merk = $("#autocomplete").val();
$("#selected-brands").append(" <a class=\"deletemerk\" href=\"#\">" + merk + "</a>");
//Add your parameters here
var param = JSON.stringify({
Brand: merk
});
$.ajax({
type: "POST",
async: true,
url: "scripttohandlejson.php",
contentType: "application/json",
data: param,
dataType: "json",
success: function (good){
//handle success
alert(good)
},
failure: function (bad){
//handle any errors
alert(bad)
}
});
return false;
});
});
PHP FILE: scripttohandlejson.php
<?PHP
$getcontent = json_decode($json, true);
$getcontent->{'Brand'};
$vraag ="INSERT INTO kijken (merk) VALUES ='$getcontent' ";
$voerin = mysql_query($vraag) or die("couldnt put into db");
<?
© Stack Overflow or respective owner