Note that there are some explanatory texts on larger screens.

plurals
  1. POUsername is not displaying PHP/MySQL
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/5202087/session-variable-not-working">_SESSION variable not working</a> </p> </blockquote> <p>Hello I know it's a common problem, but I think there's nothing wrong with my codes but I'm wondering why my <strong>$_SESSION['myusername'];</strong> is not displaying the currently logged on user.</p> <p>Below is my main.php:</p> <pre><code>&lt;?php session_start(); if(isset($_SESSION['myusername'])){ header("location: index.php"); } echo "Hello " .$_SESSION['myusername']; ?&gt; </code></pre> <p>my checklogin.php</p> <pre><code>&lt;?php session_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="dbscholaris"; // Database name $tbl_name="users"; // 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"); // username and password sent from form $myusername = $_POST['myusername']; $mypassword = $_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 "main.php" $_SESSION["myusername"] = $myusername; $_SESSION["mypassword"] = $mypassword; header("location:main.php"); } else { echo "Wrong Username or Password"; } ?&gt; </code></pre> <p>Please help me find what I'm missing. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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