Jump to content

Hello "username"!


Pandareen

Recommended Posts

Hi!i've got a big problem...i've made a login form wich works but i don't know how to make a session to store user's username and display after login "Hello username!"Can u help me please?

 

This are my pages:

 

1.login.php

<?php session_start();  

$_SESSION['logat'] = 0; 

$username = $_POST['username']; 
$password = $_POST['password']; 
$table = "xxx"; 
$name = "xxx"; 
$pass = "xxx"; 
$host = "xxx"; 
$user = "xxx"; 
$user_pass = "xxx"; 


$con = mysql_connect($host,$user,$user_pass); 
if (!$con){ 
  die('Could not connect: ' . mysql_error()); 
} 

mysql_select_db("table", $con); 


if ($_SERVER['REQUEST_METHOD'] == "POST") {  
    $query = sprintf("SELECT * FROM `$table` 
    WHERE `$name` LIKE '%s' AND `$pass` LIKE '%s'", 
    mysql_real_escape_string($username), 
    mysql_real_escape_string($password)); 

    $result = mysql_query($query) or die(mysql_error());  
    
    if(mysql_num_rows($result) > 0) { 
             
            $_SESSION['logat'] = 1;  
    }  
}  
if($_SESSION['logat'] == 0) {  
    header("error.php"); 
} else {  
    header("user.php"); 
}  
?>

 

2.user.html

<?php session_start(); 

if ($_SESSION['logat'] == 0){
header("location:http:/Proiect%20AW/loginerror.php");
}	 
else
echo "";
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>IntelliBook - Panou de Comanda</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
<link rel="icon" type="image/x-icon" href="resurse/favicon.png" />
</head>

<body>
<div id="header" title="IntelliBook v1.0"></div>
<div id="spacer"></div>

<div id="logat">

<p id="logat_text"><strong>Salut</strong>HELLO USER </p> 
<p id="logat_text">....

 

...and where is HELLO USER i want to display the user wich is logged in...

 

Link to comment
https://forums.phpfreaks.com/topic/253853-hello-username/
Share on other sites

Don't bump threads.

 

Read this: http://php.net/manual/en/language.types.array.php then try to do it on your own. If you have trouble, post the code you tried along with any errors or other problems you encountered.

Link to comment
https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301451
Share on other sites

Where you have

 $_SESSION['logat'] = 1;

 

Below, add

$_SESSION['username'] = $_POST['username'];

 

And on user.html, replace

<p id="logat_text"><strong>Salut</strong>HELLO USER </p> 

with

<p id="logat_text"><strong>Salut</strong><?php echo $_SESSION['username']; ?> </p> 

 

Although, it is not suggested you have HTML and PHP in the same file.

Link to comment
https://forums.phpfreaks.com/topic/253853-hello-username/#findComment-1301461
Share on other sites

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.