Jump to content

... i dont get it... (cant fetch from database)


sylvertwst

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/128292-i-dont-get-it-cant-fetch-from-database/
Share on other sites

::)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

Archived

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

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.