1acid Posted July 24, 2012 Share Posted July 24, 2012 Hi I am making a sign in page for a simple web app. I have user data entered into my DB already that you could use to sign in. here is my code <?php session_start(); include("functions.php"); include("config.php"); include("connect.php"); $error=array(); if(isset($_POST['signin'])) { if(empty($_POST['username'])) { $error['username'] = "Username PLZ!"; } if(empty($_POST['password'])) { $error['password'] = "PSWD PLEASE!"; } if(count($error)==0) { $cleanData =sanitize_array($_POST); $pswd = md5($cleanData['password']); $sqlStr = "SELECT id FROM calcuser WHERE username='{$cleanData['username']}'AND password='{$pswd}'"; $result = mysql_fetch_array(mysql_query($sqlStr)); if($result) { $_SESSION['$user_id']= $result['id']; redirect("index.php"); } else { $error['combi'] ="Password/username do not match records"; } } } ?> and this is my code on the redirect page that should be getting the userid from the DB and matching it with the session id user_id session_start(); include("functions.php"); include("config.php"); include("connect.php"); if(!isset($_SESSION['user_id'])) { redirect("signin.php"); } $sqlStr = "SELECT id, name, username FROM calcuser WHERE id='{$_SESSION['user_id']}'"; $row =(mysql_fetch_assoc(mysql_query($sqlStr))); its not taking me to the index page, which to me means there is something wrong with either the sql query to get the user id from the DB Any help would be greatly appreciated. Im pretty newb at all this. Thanks(Man i hope these code brackets worked!!) Link to comment https://forums.phpfreaks.com/topic/266173-help-with-sign-in-and-session-please/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 24, 2012 Share Posted July 24, 2012 Your code probably is going to the index.php page, but it is redirecting back to the signin.php page. The session variable name you are setting is - $_SESSION['$user_id']. You probably intended that to be $_SESSION['user_id'] Link to comment https://forums.phpfreaks.com/topic/266173-help-with-sign-in-and-session-please/#findComment-1364013 Share on other sites More sharing options...
1acid Posted July 24, 2012 Author Share Posted July 24, 2012 You sir are my hero!!! IT WORKS!!! Link to comment https://forums.phpfreaks.com/topic/266173-help-with-sign-in-and-session-please/#findComment-1364014 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.