Last active
November 23, 2017 13:28
-
-
Save Eyakub/ae690b3351ccb8531f8cb273d4f2ae04 to your computer and use it in GitHub Desktop.
PHP data Set & Insert
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$con = mysqli_connect("localhost","username","password","databaseName"); | |
if (mysqli_connect_errno()) | |
{ | |
echo "Failed to connect to MySQL: " . mysqli_connect_error(); | |
} | |
$jsonarray = array(); | |
$sql="SELECT * FROM table_name"; | |
$result=mysqli_query($con,$sql); | |
while($row=mysqli_fetch_assoc($result)){ | |
$temp_array['name'] = $row['name']; | |
$temp_array['email'] = $row['email']; | |
$temp_array['pp_url'] = $row['pp_url']; | |
$temp_array['fb_user_id'] = $row['fb_user_id']; | |
array_push($jsonarray, $temp_array); | |
} | |
echo json_encode($jsonarray); | |
?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$con = mysqli_connect("localhost","username","password","databaseName"); | |
if (mysqli_connect_errno()) | |
{ | |
echo "Failed to connect to MySQL: " . mysqli_connect_error(); | |
}else{ | |
mysqli_set_charset($con,"utf8"); | |
if (isset($_POST['fb_id']) && $_POST['fb_id'] != '') { | |
$fb_id = $_POST['fb_id']; | |
$user_name = $_POST['name']; | |
$email = $_POST['emailID']; | |
$pp_url = $_POST['pp_url']; | |
$insert_query = "INSERT INTO `ussoft_lict_users` (`fb_user_id`, `name`, `email`, `pp_url`) VALUES ('".$fb_id."','".$user_name."', '".$email."', '".$pp_url."')"; | |
if ($con->query($insert_query) === TRUE) { | |
echo "New record created successfully"; | |
} else { | |
echo "Error: ".$sql.$con->error; | |
} | |
} | |
else{ | |
echo "Facebook ID is missing!"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment