Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require '../koneksi.php';
- $upload_path = 'foto/';
- // $server_ip = gethostbyname(gethostname());
- // $upload_url = 'http://'.$server_ip.'/Dinacom/'.$upload_path;
- // $filename = "img".rand(9,9999).".jpg";
- $response = array();
- if ($_SERVER['REQUEST_METHOD']=='POST') {
- $nama = $_POST['nama'];
- $username = $_POST['username'];
- $no_telp = $_POST['no_telp'];
- $alamat = $_POST['alamat'];
- $email = $_POST['email'];
- $jenis_kelamin = $_POST['jenis_kelamin'];
- $password = md5($_POST['password']);
- $level = $_POST['level'];
- // echo $file_name;
- // $fileinfo = pathinfo($_FILES['foto']['name']);
- // $extension = $fileinfo['extension'];
- // $file_path = $upload_path . $_FILES['foto']['name'];
- $sql = "SELECT * FROM tb_user WHERE username = '$username'";
- $check = mysqli_fetch_array(mysqli_query($conn, $sql));
- if (isset($check)) {
- $response["result"] = "-1";
- $response["msg"] = "Username sudah terdaftar!";
- }else{
- try {
- // move_uploaded_file($_FILES['foto']['tmp_name'], $file_path);
- if($_SERVER['REQUEST_METHOD'] == 'POST') {
- if($_FILES['foto']) {
- $file_url = $_FILES['foto']['nama'];
- $destination_file = $upload_path. $_FILES['foto']['nama'];
- if(move_uploaded_file($_FILES['foto']['tmp_name'], $destination_file)) {
- $sql = "INSERT INTO tb_user ( nama, username, no_telp, alamat, email, jenis_kelamin, foto, level) VALUES ( '$nama', '$username', '$no_telp', '$alamat',
- '$jenis_kelamin', '$file_url', '$level');";
- $eksekusi = mysqli_query($conn, $sql);
- if($eksekusi) {
- $response['result'] = "1";
- $response['msg'] = "Berhasil Register!!";
- # code...
- } else {
- $response['result'] = "0";
- $response['msg'] = "Gagal Register!!";
- }
- }
- }
- }else{
- $response['result'] = "-2";
- $response['msg'] = "Request tidak valid";
- }
- }catch (Exception $e) {
- $response['error'] = true;
- $response['message'] = $e->getMessage();
- }
- }
- echo json_encode($response);
- mysqli_close($conn);
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement