Jump to content

Log In With A Role Value


elexion

Recommended Posts

$rij = mysql_fetch_array($result, $query);echo $rij['username'];$_SESSION['username']= "'{$_POST['username']}'";$_SESSION['role'] = "'{$_POST['role']}'";session_write_close();header("location: index.php");

that does give me a better output on the whole picture yes;Array ( [username] => 'admin' [role] => '' ) but when i add another AND to my query to get the role value out of the database i get a error while logging in.

You're not looking for $_POST['role']. I thought we already determined that the user does not have to tell what role he has. $_POST is only for user input.You're supposed to extract the role information from the database.By the way, you have a whole lot of unnecessary quotes and braces here:
$_SESSION['username']= "'{$_POST['username']}'";

Just set the variable to the value of the other one:

$_SESSION['username']= $_POST['username'];

Link to comment
Share on other sites

should i use $_GET or something i'm completely lost because i dont understand why it's not taking the role value out of my database since i'm using "select * FROM docenten" that means it takes everything out of the database right?

Link to comment
Share on other sites

Yes... but it doesn't then place it in the $_POST array (unless you tell it to, but that would be weird)! It goes into the array in which you stored the result of the mysql_fetch_array() function.

Link to comment
Share on other sites

Yes... but it doesn't then place it in the $_POST array (unless you tell it to, but that would be weird)! It goes into the array in which you stored the result of the mysql_fetch_array() function.
hmm well i conjured up this line
 $_SESSION['role'] = $rij['role'];

but that can't be right cause it's still not returning anything either i'm seriously the king of bugs or i'm just not getting it.

Link to comment
Share on other sites

Are you putting it somewhere around:

$query = "SELECT * from tableWHERE username = '{$_POST['username']}'AND password = '".$password."'";$result = mysql_query($query, $db) or die('the query failed');if (mysql_num_rows($result) > 0){$rij = mysql_fetch_array($result, $query);echo $rij['username'];$_SESSION['username']= "'{$_POST['username']}'";session_write_close();header("location: index.php");}

Also, print_r($rij) to see what it contains.

Link to comment
Share on other sites

Are you putting it somewhere around:
$query = "SELECT * from tableWHERE username = '{$_POST['username']}'AND password = '".$password."'";$result = mysql_query($query, $db) or die('the query failed');if (mysql_num_rows($result) > 0){$rij = mysql_fetch_array($result, $query);echo $rij['username'];$_SESSION['username']= "'{$_POST['username']}'";session_write_close();header("location: index.php");}

Also, print_r($rij) to see what it contains.

$password = ($_POST["password"]);$query = "select * FROM docentenWHERE username = '{$_POST['username']}'AND password = '".$password."'";$result = mysql_query($query, $db) or die('the query failed');if (mysql_num_rows($result) > 0){$rij = mysql_fetch_array($result, $query);echo $rij['username'];echo $rij['role'];print_r($rij);$_SESSION['username']= $_POST['username'];$_SESSION['role'] = $rij['role'];session_write_close();header("location: index.php");}

i can't print the print_r($rij) outside of the logIn script above. but the script smoothly picks out the username so it's pretty frustrating not getting this thing

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...