- This topic is empty.
Viewing 1 post (of 1 total)
Viewing 1 post (of 1 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hi!
I’m trying to use the variable $username in my index.php (I want to echo out Logged in as ‘$username’).
I set the variable $username and register a session in my checklogin.php, but I cant seem to use it when I’m in my index.php.
I am probably doing something wrong here, but I can’t see what, I need your help finding a solution to this problem :)
Code from index.php
Webb B
session_start();
$username = $_SESSION;
if (!session_is_registered(username)) {
echo '';
}
else {
echo 'Inloggad som ' . $username . '!
';
echo '';
}
?>
and checklogin.php
ob_start(); ?>
Webb B
require_once "scripts/login.php";
// error_reporting(E_ALL); ini_set('display_errors', 'On');
$username = $_POST;
$password = $_POST;
// $username = stripslashes($username);
// $password = stripslashes($password);
// $username = mysql_real_escape_string($username);
// $password = mysql_real_escape_string($password);
$sqlCommand = "SELECT * FROM members WHERE membername='$username' AND memberpassword='$password'";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$num_rows = mysqli_num_rows($query);
if ($num_rows == 1) {
session_register("username");
session_register("password");
header("location: index.php");
}
else {
echo 'Fel! Försök igen!';
}
?>
ob_flush(); ?>
Can anyone explain to me why I can’t use the variable $username?