Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- header('Access-Control-Allow-Origin: *');
- header('Content-Type: application/json; charset=UTF-8');
- header('Access-Control-Allow-Methods: POST, GET, DELETE, PUT');
- header('Access-Control-Max-Age: 3600');
- header('Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With');
- #BERI NAMA FILE DENGAN supplier-000.php
- include 'database.php';
- $db = new Database();
- switch ($_SERVER['REQUEST_METHOD']) { //jenis method
- case 'POST':
- $db->open();
- switch ($_REQUEST['action']){
- case 'simpan':
- $sql = 'insert into supplier values("'. $_REQUEST['id'] .'", ';
- $sql .= '"'. $_REQUEST['nama'] .'", "'. $_REQUEST['alamat'] .'", ';
- $sql .= '"'. $_REQUEST['telp'] .'", "'. $_REQUEST['email'] .'", ';
- $sql .= '"'. $_REQUEST['pic'] .'")';
- break;
- case 'ubah':
- $sql = 'update supplier set namasupplier = "'. $_REQUEST['nama'] .'", ';
- $sql .= 'alamatsupplier = "'. $_REQUEST['alamat'] .'", ';
- $sql .= 'telpsupplier = "'. $_REQUEST['telp'] .'", ';
- $sql .= 'emailsupplier = "'. $_REQUEST['email'] .'", ';
- $sql .= 'picsupplier = "'. $_REQUEST['pic'] .'" ';
- $sql .= 'where idsupplier = "'. $_REQUEST['id'] .'"';
- break;
- case 'hapus':
- $sql = 'delete from supplier where idsupplier ="'. $_REQUEST['id'] .'"';
- break;
- }
- $result = [
- 'result' => $db->execute($sql)
- ];
- $db->close();
- print json_encode( $result );
- break;
- case 'GET':
- $db->open();
- $result = [
- 'result' => $db->get('select * from supplier')
- ];
- $db->close();
- print json_encode( $result );
- break;
- default:
- http_response_code(400); //kode bad request
- $result = [
- 'result' => null
- ];
- print json_encode( $result );
- break;
- }
- ?>
Add Comment
Please, Sign In to add comment