justsomeguy Posted January 21, 2010 Share Posted January 21, 2010 You shouldn't need to add anything to the query, you're already selecting all of the fields from the table. Link to comment Share on other sites More sharing options...
Ingolme Posted January 21, 2010 Share Posted January 21, 2010 $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 More sharing options...
elexion Posted January 25, 2010 Author Share Posted January 25, 2010 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 More sharing options...
Synook Posted January 25, 2010 Share Posted January 25, 2010 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 More sharing options...
elexion Posted January 25, 2010 Author Share Posted January 25, 2010 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 More sharing options...
Synook Posted January 25, 2010 Share Posted January 25, 2010 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 More sharing options...
elexion Posted January 25, 2010 Author Share Posted January 25, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.