sylvertwst Posted October 13, 2008 Share Posted October 13, 2008 hello. i've been studying this code letter by letter and i seriously have no idea what i'm doing wrong. what seems to be the problem is that the sql command returns nothing, while it should. the database has a table 'users' with fields user_id, user_name and user_password. (yeah.. a login tutorial from a book... i'm starting to think the book is flawed. lol.) the vars from the form on the previous page are fine, as when i get that echo, they show up. the ones from the sql query dont... there isnt even an error report. the sql request array is just empty. i confirmed that with checking if $sql_login_check is set or not. please help me clear this i'm so eager to learn lol i get frustrated when i get stuck on stuff like this. <?php include('include/db_connect.php'); //get submitted credentials $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; //secure credentials against code-injection to protect database $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); //compare user/pw to records in database $login_check="select * from users where user_password='$mypassword'"; $sql_login_check = mysql_query("$login_check"); $sql_username=$sql_login_check['user_name']; $sql_password=$sql_login_check['user_password']; $sql_id=$sql_login_check['user_id']; if($sql_username!=$myusername || $sql_password!=$mypassword){ //login failed echo("login failed. incorrect username/password<br /><br />"); //errornotes for debug purposes echo('username provided: ' . $myusername .'<br />'); echo('password provided: ' . $mypassword .'<br /><br />'); echo('username mysql: ' . $sql_username .'<br />'); echo('password mysql: ' . $sql_password .'<br />'); echo('ID mysql: ' . $sql_id .'<br />'); }else{ //login succes! register the provided username and pass to the session session_register("myusername"); session_register("mypassword"); //redirect to login_succes.php header("location: login_succes.php"); } ?> <body> </body> <?php include('include/footer.php');?> many thanks, Sylv Quote Link to comment https://forums.phpfreaks.com/topic/128292-i-dont-get-it-cant-fetch-from-database/ Share on other sites More sharing options...
DarkWater Posted October 13, 2008 Share Posted October 13, 2008 You didn't actually call mysql_fetch_array() or any of the mysql_fetch_* functions to get the data out of the result resource from mysql_query(). Quote Link to comment https://forums.phpfreaks.com/topic/128292-i-dont-get-it-cant-fetch-from-database/#findComment-664545 Share on other sites More sharing options...
sylvertwst Posted October 14, 2008 Author Share Posted October 14, 2008 ::)DOH okay stage cleared.. it seems i am using sessionvars in a wrong way. if session_register("myusername"); has been done i should be able to get it simply with $myusername .. right? egh i could probably figure this one out... using google. >< forgive me for being lazy at 2 am and if this is gainst policies tell me:p i'll set it to solved as my initial question(wasnt that a hard one) has been answered Quote Link to comment https://forums.phpfreaks.com/topic/128292-i-dont-get-it-cant-fetch-from-database/#findComment-664568 Share on other sites More sharing options...
.josh Posted October 14, 2008 Share Posted October 14, 2008 session_register is deprecated. Use $_SESSION['myusername'] instead. No declaring or anything. Quote Link to comment https://forums.phpfreaks.com/topic/128292-i-dont-get-it-cant-fetch-from-database/#findComment-664571 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.