alert('One Record Deleted');"; } //fungsi cari mahasiswa function srchmhs($search){ $sql = ""; $query = mysql_query($sql); return $query; } //fungsi select mahasiswa function slcmhs($id){ $sql = "SELECT * FROM mahasiswa WHERE nim=$id"; //echo $sql; $query = mysql_query($sql); //var_dump($query); return $query; } //fungsi insert mahasiswa function insmhs(){ $nim = $_POST['nim']; $nama = $_POST['nama']; $telp = $_POST['telp']; $asal = $_POST['asal']; $alamat = $_POST['alamat']; $foto = foto($_FILES,$nim); $sql = "INSERT INTO mahasiswa (nim,nama,alamat,telp,asal,foto) VALUES ($nim,'$nama','$alamat','$telp','$asal','$foto')"; //echo $sql; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } header('Location: index.php'); } function foto($file,$id){ $allowedExts = array("gif", "jpeg", "jpg", "png"); $temp = explode(".", $file["file"]["name"]); $extension = end($temp); if ((($file["file"]["type"] == "image/gif") || ($file["file"]["type"] == "image/jpeg") || ($file["file"]["type"] == "image/jpg") || ($file["file"]["type"] == "image/pjpeg") || ($file["file"]["type"] == "image/x-png") || ($file["file"]["type"] == "image/png")) //&& ($file["file"]["size"] < 20000) && in_array($extension, $allowedExts)) { if ($file["file"]["error"] > 0) { echo "Return Code: " . $file["file"]["error"] . "
"; } else { if (file_exists("upload/" . $id.".".$extension)) { echo $id . " already exists. "; } else { move_uploaded_file($file["file"]["tmp_name"], "upload/" . $id.".".$extension); $lokasi = "upload/" . $id.".".$extension; return $lokasi; } } } else { echo "Invalid file"; } } if (isset($_GET['action'])) $func=$_GET['action']; else $func=''; switch($func){ case 'delete' : $id = $_GET['id']; delmhs($id); break; case 'update' : $id = $_GET['id']; updmhs($id); break; case 'insert' : insmhs(); break; default : //echo 'no run'; } ?>