Jump to content

Help with sign in and session please


1acid

Recommended Posts

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.