mysql - user access level in PHP -


my problem maybe simple problem whom expert, still cant understand put loop code

where should put :

while($row=mysql_fetch_array($query)) {     if($row['level']==1)     {         header('location: home.php');     }     else if($row['level']==2)     {         header('location: home2.php');     }     else if($row['level']==3)     {         header('location: home3.php');     }  } 

in :

`<?php session_start(); $id = mysql_real_escape_string($_post['id']); $katalaluan = mysql_real_escape_string($_post['katalaluan']);   mysql_connect("localhost", "root","") or die(mysql_error()); //connect server mysql_select_db("sistem_laporan") or die("cannot connect database"); //connect database   $query = mysql_query("select * profil id='$id'"); //query profil table if there matching rows equal $id $exists = mysql_num_rows($query); //checks if id exists $table_profil = ""; $table_katalaluan = "";  if($exists > 0) //if there no returning rows or no existing id {     while($row = mysql_fetch_assoc($query)) //display rows query     {         $table_profil = $row['id']; // first id row passed on $table_profil, , on until query finished         $table_katalaluan = $row['katalaluan']; // first password row passed on $table_profil, , on until query finished       }     if(($id == $table_profil) && ($katalaluan == $table_katalaluan)) // checks if there matching fields     {             if($katalaluan == $table_katalaluan)             {                 $_session['id'] = $id; //set id in session. serves global variable                  header("location: home.php"); // redirects user authenticated home page              }      }     else     {         print '<script>alert("kata laluan dimasukkan adalah salah!");</script>'; //prompts user         print '<script>window.location.assign("login.php");</script>'; // redirects login.php     }  } else {     print '<script>alert("id pengguna dimasukkan adalah salah!");</script>'; //prompts user     print '<script>window.location.assign("login.php");</script>'; // redirects login.php } ?>` 

the main thing want redirect different level(1-admin 2-assistant 3-director) different page didnt know put while loop in main code without changing structure of main code.hope can me. sorry bad english.thanks.

you don't need while loop identify user type since exist. have add conditional statements under if($katalaluan == $table_katalaluan)

mysql_connect("localhost", "root","") or die(mysql_error()); //connect server mysql_select_db("sistem_laporan") or die("cannot connect database"); //connect database   $query = mysql_query("select * profil id='$id'"); //query profil table if there matching rows equal $id $exists = mysql_num_rows($query); //checks if id exists $table_profil = ""; $table_katalaluan = "";  if($exists > 0) //if there no returning rows or no existing id {     while($row = mysql_fetch_assoc($query)) //display rows query     {         $table_profil = $row['id']; // first id row passed on $table_profil, , on until query finished         $table_katalaluan = $row['katalaluan']; // first password row passed on $table_profil, , on until query finished       }     if(($id == $table_profil) && ($katalaluan == $table_katalaluan)) // checks if there matching fields     {             if($katalaluan == $table_katalaluan)             {                 $_session['id'] = $id; //set id in session. serves global variable                  if($row['level']==1)                     {                         header('location: home.php');                     }                     else if($row['level']==2)                     {                         header('location: home2.php');                     }                     else if($row['level']==3)                     {                         header('location: home3.php');                     }              }      }     else     {         print '<script>alert("kata laluan dimasukkan adalah salah!");</script>'; //prompts user         print '<script>window.location.assign("login.php");</script>'; // redirects login.php     }  } else {     print '<script>alert("id pengguna dimasukkan adalah salah!");</script>'; //prompts user     print '<script>window.location.assign("login.php");</script>'; // redirects login.php } 

Comments

Popular posts from this blog

javascript - Jquery show_hide, what to add in order to make the page scroll to the bottom of the hidden field once button is clicked -

javascript - Highcharts multi-color line -

javascript - Enter key does not work in search box -