Assalamualaikum,
Mas mau tanya, saya membuat form login multi user,pas saya coba login ga bisa masuk malah eror password salah, padahal password udah benar, kira-kira script saya salah pada bagian mana? mohon pencerahan saya ingin belajar php.
ini script loginnya :
<?php
session_start();
require_once('config/koneksi.php');
$login = clean($_POST['login']);
$password = clean($_POST['password']);
$user_type = clean($_POST['user']);
$errmsg_arr = array();
$errflag = false;
if($login == '' && $password == '' && $user_type == '') {
header("location: index.php");
exit();
}
if($login == '') {
$errmsg_arr[0] .= 'NIS / NIP / Email tidak boleh kosong<br />';
$errflag = true;
}
if($password == '') {
$errmsg_arr[0] .= 'Password tidak boleh kosong<br />';
$errflag = true;
}
if($user_type == '') {
$errmsg_arr[0] .= 'Tipe login tidak boleh kosong<br />';
$errflag = true;
}
if($user_type!='') {
if($user_type=='admin' || $user_type=='guru' || $user_type=='siswa') {
if($user_type=='admin' || $user_type=='guru') {
$user_id = 'nip';
} elseif($user_type=='siswa') {
$user_id = 'nis';
}
$qry="SELECT * FROM $user_type WHERE $user_id='$login' AND password='".md5($_POST['password'])."'";
$res=mysql_query($qry);
if(!$num=mysql_num_rows($res)) {
$qry="SELECT * FROM $user_type WHERE $user_id='$login' AND password=''";
$res=mysql_query($qry);
if($num=mysql_num_rows($res) && $login<>$password) {
$errmsg_arr[0] = 'Password Salah<br />';
$errflag = true;
}
}
}
if($user_type=='alumni' || $user_type=='orangtua') {
$user_id = 'email';
$qry="SELECT * FROM $user_type WHERE $user_id='$login' AND password='".md5($_POST['password'])."'";
$res=mysql_query($qry);
if(!$num=mysql_num_rows($res)) {
$errmsg_arr[0] = 'Password salah<br />';
$errflag = true;
} else {
$qry="SELECT * FROM $user_type WHERE $user_id='$login' AND password='".md5($_POST['password'])."' AND kode=''";
$res=mysql_query($qry);
if(!$num=mysql_num_rows($res)) {
$errmsg_arr[0] = 'Anda belum melakukan aktifasi,<br />silakan periksa email terlebih dahulu<br />';
$errflag = true;
}
}
}
}
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: error.php");
exit();
}
$result=mysql_query($qry);
if($result) {
if(mysql_num_rows($result) == 1) {
session_regenerate_id();
$user = mysql_fetch_assoc($result);
$_SESSION['SESS_USER_ID'] = $user[$user_id];
$_SESSION['SESS_USER_NAMA'] = $user['nama'];
$_SESSION['SESS_USER_PASSWORD'] = $user['password'];
$_SESSION['SESS_USER_EMAIL'] = $user['email'];
$_SESSION['SESS_USER_TYPE'] = $user_type;
$_SESSION['SESS_USER_JKELAMIN'] = $user['jeniskelamin'];
$_SESSION['SESS_USER_TEMLAHIR'] = $user['tempatlahir'];
$_SESSION['SESS_USER_TGLLAHIR'] = $user['tgllahir'];
$_SESSION['SESS_USER_ALAMAT'] = $user['alamat'];
$_SESSION['SESS_USER_STATUS'] = $user['status'];
if(($user_type=='admin') || ($user_type=='guru')) {
$_SESSION['SESS_USER_PENDIDIKAN'] = $user['pendidikan'];
$_SESSION['SESS_USER_STATPEGAWAI'] = $user['statuskepegawaian'];
}
if(($user_type=='siswa') || ($user_type=='alumni')) {
$_SESSION['SESS_USER_THNMASUK'] = $user['tahunmasuk'];
}
if($user_type=='siswa') {
$_SESSION['SESS_USER_NAMAORTU'] = $user['namaorangtua'];
$_SESSION['SESS_USER_KERJAORTU'] = $user['pekerjaanorangtua'];
}
if($user_type=='alumni') {
$_SESSION['SESS_USER_THNKELUAR'] = $user['tahunkeluar'];
$_SESSION['SESS_USER_PEKERJAAN'] = $user['pekerjaan'];
}
if($user_type=='orangtua') {
$_SESSION['SESS_USER_NIS'] = $user['nis'];
$_SESSION['SESS_USER_PEKERJAAN'] = $user['pekerjaan'];
}
$_SESSION['ERRMSG_ARR'][0] = "Anda login sebagai ".$_SESSION['SESS_USER_NAMA'].", selamat datang kembali.";
session_write_close();
header("location: index.php");
exit();
}else {
$_SESSION['ERRMSG_ARR'][0] = "Password salah";
session_write_close();
header("location: error.php");
exit();
}
}else {
die("Query gagal : ".mysql_error());
}
?>