<?php include'connection.php'; /* this function is to sanitze values recevied from form.*/ function clean ($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } $username = clean ( $_POST['email']); $password = clean (md5($_POST['password'])); $result = mysql_query("SELECT * FROM tbluser_login WHERE user_Email='".$username."' AND user_Password='".$password."'"); /*echo mysql_num_rows($result);*/ $result2 = mysql_query("SELECT user_Category FROM tbluser_login WHERE user_Email='".$username."'"); $result3 = mysql_fetch_row($result2); /*echo mysql_num_rows($rsult2); print_r(mysql_fetch_row($result2));*/ if ($result){ if(mysql_num_rows($result)== 0){ /* arrays starts from 0 and we will get one array at a time.*/ session_regenerate_id(); $login = mysql_fetch_assoc($result); $_SESSION['SESS_username']= $login['user_Email']; $_SESSION['SESS_usercategory'] = $login['user_Category']; $_SESSION['SESS_pasword'] = $login['user_Password']; session_write_close(); switch($result3[0]){ case 'Tutor': header("location: tutor_profile.php"); echo''.$login; break; case 'Staff': header("location: staff_profile.php"); break; case 'Student': header("location: student_profile.php"); break; case 'Administrator': header("location: admin_profile.php"); break; default: die("case not working"); } } else { echo("error".error_reporting(E_ALL)); exit; } } ?>
this code redirects me in appropriate profile page. but problem is how can i retrieve data from database as based user login. please anybody help me!!
Well, you can either make certain DB requests on those pages, or in the login page put the information you need in the session and retrieve it in the successive pages.
Ashley says right,
you can try it, it may be done proper way.