Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9259209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T12:35:59+00:00 2026-06-18T12:35:59+00:00

I’m currently learning to work with sessions and alike things, and I’m trying to

  • 0

I’m currently learning to work with sessions and alike things, and I’m trying to make some simple log-in system, but I can’t seem to pass variables from one page to the next.

login_confirm.php

<?php
session_start("session");
$host="localhost"; // Host name 
$username="*"; // Mysql username 
$password="*"; // Mysql password 
$db_name="*"; // Database name 
$tbl_name="members"; // Table name 

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");

// Define $myusername and $mypassword 
$myusername=$_POST['myusername'];
$mypassword=hash('sha256', $_POST['mypassword']);

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);

// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){

// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 

$_SESSION['_username']=$myusername;

header("location:login_success.php");

}
else {
echo "Wrong Username or Password.";
}
ob_end_flush();
?>

login_success.php

<?php
session_start();
if(!session_is_registered(myusername)){
//header("location:login.php");
 echo $_SESSION['_username']; 
}
?>

Basically it wont even echo the $_SESSION['_username'];

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T12:36:01+00:00Added an answer on June 18, 2026 at 12:36 pm

    Really you should be using PDO or mysqli as mysql_* functions are soon tobe DEPRECATED. Must be a really old tutorial

    Here is a port of you code using PDO

    <?php
    session_start();
    // SQL Config
    $config['sql_host']='localhost';
    $config['sql_db']  ='members';
    $config['sql_user']='*';
    $config['sql_pass']='*';
    
    // SQL Connect
    try {
            $db = new PDO("mysql:host=".$config['sql_host'].";dbname=".$config['sql_db'], $config['sql_user'], $config['sql_pass']);
            $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
            $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    }catch (Exception $e){
            echo ('Cannot connect to mySQL server.');
    }
    
    // Check for POST, add isset($_POST['myusername']) ect to add validations
    if($_SERVER['REQUEST_METHOD']=='POST'){
       // Build your query with placeholders
       $sql = "SELECT 1 FROM members WHERE username=:username && password=:password";
    
        // Prepare it
        $statement = $db->prepare($sql);
        // Assign your vairables to the placeholders
        $statement->bindParam(':username', $_POST['myusername']);
        $statement->bindValue(':password', hash('sha256', $_POST['mypassword']));
    
        // Execute the query
        $statement->execute();
        //Fetch the result
        $result = $statement->fetch(PDO::FETCH_ASSOC);
        //Is it not empty else
        if(!empty($result)){
                //$_SESSION['logged_in'] in login_success.php
            $_SESSION['logged_in'] = true;
            $_SESSION['username'] = $_POST['myusername'];
            exit(header("Location: ./login_success.php"));
        }else{
            $_SESSION['logged_in'] = false;
                //pass error to login 
            $_SESSION['error'] = 'Username or password wrong bla';
            exit(header("Location: ./login.php"));
        }
    }
    ?>
    

    Hope it helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Seemingly simple, but I cannot find anything relevant on the web. What is the
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.