Hi I'm trying to insert the json array into my MySQL database. but I have a problem if I insert my Json data and try to insert into my database, display in browser is empty. I dont know how to fix it, please tell me and help me for this.
Here its my json data
[{"id_peneliti":1083,"id_prodi":"4","nama_lengkap":"hasil edit","nama_tampilan":"duplikat","nip":"11111111222222222222","foto_user":"img\/foto\/2b8a1f40237e7f58bf0f7376fc8d5288.jpeg","email":"[email protected]","phone":"+39ry982835982","riwayat_pendidikan":"
sfbvxlkmblfkblkn<\/p>\r\n"}]
here is my parsing json
<?
$json_url = "http://localhost/location/create_jsoninput.php";
$json = file_get_contents($json_url);
$data = json_decode($json,true);
//Database Connection
mysql_connect("localhost","name","pass") or die(mysql_error());
mysql_select_db("db_name") or die(mysql_error());
if (foreach ($data as $item)) {
mysql_query("INSERT INTO tb_database VALUES ('".$item['id_peneliti']."','".$item['id_prodi']."', '".$item['nama_lengkap']."', '".$item['nama_tampilan']."', '".$item['nip']."', '".$item['password']."',
'".$item['name']."', '".$item['email']."')");
mysql_close();
echo "Data Berhasil Disimpan...";
}else{
echo "Data Gagal, Tersimpan...";
}
?>
Please help me...
mysql_error()and this... click me, I won't bite, too hard.foreach.mysql_*functions, They are no longer maintained and are officially deprecated. Learn about prepared statements instead, and use PDO or MySQLi. You will also want to Prevent SQL Injection!if (foreach ...))is not valid PHP syntax. How is this code even running?