Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $json = file_get_contents('php://input');
- $obj = json_decode($data,true);
- //Database Connection
- require_once 'db.php';
- /* insert data into DB */
- 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']."')");
- }
- //database connection close
- mysql_close($con);
- //}
- ?>
- <?php
- //ENTER YOUR DATABASE CONNECTION INFO BELOW:
- $hostname="localhost";
- $database="dbname";
- $username="username";
- $password="password";
- //DO NOT EDIT BELOW THIS LINE
- $link = mysql_connect($hostname, $username, $password);
- mysql_select_db($database) or die('Could not select database');
- ?>
- $json = file_get_contents('php://input');
- $obj = json_decode($json,true);
- $obj = json_decode($json,true);
- <?php
- require_once('dbconnect.php');
- // reading json file
- $json = file_get_contents('userdata.json');
- //converting json object to php associative array
- $data = json_decode($json, true);
- // processing the array of objects
- foreach ($data as $user) {
- $firstname = $user['firstname'];
- $lastname = $user['lastname'];
- $gender = $user['firstname'];
- $username = $user['username'];
- // preparing statement for insert query
- $st = mysqli_prepare($connection, 'INSERT INTO users(firstname, lastname, gender, username) VALUES (?, ?, ?, ?)');
- // bind variables to insert query params
- mysqli_stmt_bind_param($st, 'ssss', $firstname, $lastname, $gender, $username);
- // executing insert query
- mysqli_stmt_execute($st);
- }
- ?>
- $string=mysql_real_escape_string($json);
Add Comment
Please, Sign In to add comment