Note that there are some explanatory texts on larger screens.

plurals
  1. POCant echo Session user php
    text
    copied!<p>The if is working but the printed username is "username" and it should be the real username that in this case is "teste". maybe i need a variable or something to display it after but I'm not getting there :s</p> <p>This is my Session starter code : </p> <pre><code>&lt;?php session_start(); ob_start(); $host="localhost"; // Nome do Host $username="segu24img"; // Mysql username $password="desny"; // Mysql password $db_name="segurao_imagem"; // Nome base de dados $tbl_name="users"; // Nome da tabela // 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"); // username and password sent from form $username=$_POST['username']; $password=$_POST['password']; // To protect MySQL injection (more detail about MySQL injection) $username = stripslashes($username); $password = stripslashes($password); $username = mysql_real_escape_string($username); $password = mysql_real_escape_string($password); $sql="SELECT * FROM $tbl_name WHERE username='$username' and password='$password'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $username and $password, table row must be 1 row if($count==1){ // Register $username, $password and redirect to file "login_success.php" $_SESSION['username'] = 'username'; //session_register("username"); $_SESSION['password'] = 'password'; //session_register("password"); header("location:login_sucess.php"); } else { echo "Wrong Username or Password"; } ?&gt; </code></pre> <p>Im using this code to display the username of session :</p> <pre><code>&lt;?php if(isset($_SESSION['username'])){ ?&gt; &lt;/p&gt; &lt;p&gt;Bem Vindo&lt;u&gt;&lt;?php echo $_SESSION['username']; ?&gt;&lt;/u&gt;- &lt;a href="logout.php"&gt;Logout&lt;/a&gt;&lt;/p&gt; &lt;?php } else{ ?&gt; &lt;p&gt;&lt;a href="#login-box" class="login-window"&gt;Login&lt;/a&gt;&lt;/p&gt; &lt;?php } ?&gt;&lt;/p&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload