Hi, I am trying to insert a json array into my MySQL database. I submit the data form of my iphone, there I converted the data to json format, and I transfer the data to my server using a URL that it does not insert into my server.
This is my json data.
[{"Name": "0", "phone": "DSF", "city": "sdfsdf", "email": "DSF"}, {"name": "13123123", "phone": " sdfsdfdsfsd "," city ":" sdfsf "," email ":" 13123123 "}]
This is my php code.
<?php
$json = file_get_contents('php://input');
$obj = json_decode($data,true);
require_once 'db.php';
foreach($obj as $item) {
mysql_query("INSERT INTO `database name`.`table name` (name, phone, city, email)
VALUES ('".$item['name']."', '".$item['phone']."', '".$item['city']."', '".$item['email']."')");
}
mysql_close($con);
?>
My database connection code.
<?php
$hostname="localhost";
$database="dbname";
$username="username";
$password="password";
$link = mysql_connect($hostname, $username, $password);
mysql_select_db($database) or die('Could not select database');
?>
, . php. , php , , , .