Last active
February 4, 2018 10:56
-
-
Save serdoune/82b2d86be82cc908a71c7c7cfd1fb7ac to your computer and use it in GitHub Desktop.
This file contains 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 | |
define('hostname', 'localhost'); | |
define('user', 'root'); | |
define('password', ''); | |
define('databaseName', 'tutorial'); | |
$connect = mysqli_connect(hostname, user, password, databaseName); | |
?> |
This file contains 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 | |
if($_SERVER["REQUEST_METHOD"]=="POST"){ | |
require 'connection.php'; | |
createStudent(); | |
} | |
function createStudent() | |
{ | |
global $connect; | |
$firstname = $_POST["firstname"]; | |
$lastname = $_POST["lastname"]; | |
$age = $_POST["age"]; | |
$query = " Insert into student(firstname,lastname,age) values ('$firstname','$lastname','$age');"; | |
mysqli_query($connect, $query) or die (mysqli_error($connect)); | |
mysqli_close($connect); | |
} | |
?> |
This file contains 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 | |
if($_SERVER["REQUEST_METHOD"]=="POST"){ | |
include 'connection.php'; | |
showStudent(); | |
} | |
function showStudent() | |
{ | |
global $connect; | |
$query = " Select * FROM STUDENT; "; | |
$result = mysqli_query($connect, $query); | |
$number_of_rows = mysqli_num_rows($result); | |
$temp_array = array(); | |
if($number_of_rows > 0) { | |
while ($row = mysqli_fetch_assoc($result)) { | |
$temp_array[] = $row; | |
} | |
} | |
header('Content-Type: application/json'); | |
echo json_encode(array("students"=>$temp_array)); | |
mysqli_close($connect); | |
} | |
?> |
This file contains 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 | |
if($_SERVER["REQUEST_METHOD"]=="POST"){ | |
require 'connection.php'; | |
createStudent(); | |
} | |
function createStudent() | |
{ | |
global $connect; | |
$firstname = $_POST["firstname"]; | |
$lastname = $_POST["lastname"]; | |
$age = $_POST["age"]; | |
$query = " Insert into student(firstname,lastname,age) values ('$firstname','$lastname','$age');"; | |
mysqli_query($connect, $query) or die (mysqli_error($connect)); | |
mysqli_close($connect); | |
} | |
?> | |
<?php | |
if($_SERVER["REQUEST_METHOD"]=="POST"){ | |
include 'connection.php'; | |
showStudent(); | |
} | |
function showStudent() | |
{ | |
global $connect; | |
$query = " Select * FROM STUDENT; "; | |
$result = mysqli_query($connect, $query); | |
$number_of_rows = mysqli_num_rows($result); | |
$temp_array = array(); | |
if($number_of_rows > 0) { | |
while ($row = mysqli_fetch_assoc($result)) { | |
$temp_array[] = $row; | |
} | |
} | |
header('Content-Type: application/json'); | |
echo json_encode(array("students"=>$temp_array)); | |
mysqli_close($connect); | |
} | |
?> | |
<?php | |
define('hostname', 'localhost'); | |
define('user', 'root'); | |
define('password', ''); | |
define('databaseName', 'tutorial'); | |
$connect = mysqli_connect(hostname, user, password, databaseName); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment