-Aplikasi CRUD Android menggunakan database MySql dan PHP-
2. Membuat script coding CRUD di PHP
a) dbConnect.php
<?php
//Defining Constants
define('HOST','localhost');
define('USER','root');
define('PASS','');
define('DB','dbmahasiswa');
//Connecting to Database
$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');
?>
//Defining Constants
define('HOST','localhost');
define('USER','root');
define('PASS','');
define('DB','dbmahasiswa');
//Connecting to Database
$con = mysqli_connect(HOST,USER,PASS,DB) or die('Unable to Connect');
?>
b) tambahMahasiswa.php
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$nama= $_POST['nama'];
$npm= $_POST['npm'];
$kelas= $_POST['kelas'];
$sql = "INSERT INTO t_mahasiswa (nama,npm,kelas) VALUES ('$nama','$npm','$kelas')";
require_once('dbConnect.php');
if(mysqli_query($con,$sql)){
echo 'Mahasiswa Added Successfully';
}else{
echo 'Could Not Add Mahasiswa';
}
mysqli_close($con);
}
if($_SERVER['REQUEST_METHOD']=='POST'){
$nama= $_POST['nama'];
$npm= $_POST['npm'];
$kelas= $_POST['kelas'];
$sql = "INSERT INTO t_mahasiswa (nama,npm,kelas) VALUES ('$nama','$npm','$kelas')";
require_once('dbConnect.php');
if(mysqli_query($con,$sql)){
echo 'Mahasiswa Added Successfully';
}else{
echo 'Could Not Add Mahasiswa';
}
mysqli_close($con);
}
Comments
Post a Comment