I have the following code in my php files, but i am having a following error while loading my page?
"Notice: Undefined variable: username in C:\xampp\htdocs\fyp\cms\cms.php on line 48"
My page is successfully loading up, but username is not being shown in the page and the error is popped up in it.
Can someone tell whats the error here?
login.php
<?php include_once("../includes/connection.php");?>
<!DOCTYPE html>
<?php
session_start();
?>
<html lang='en'>
<head>
<meta charset="UTF-8" />
<title>
HTML Document Structure
</title>
<link rel="stylesheet" type="text/css" href="style.css" />
</head>
<body>
<div id="wrapper">
<?php
$current_page = $_SERVER['PHP_SELF'];
?>
<form name="login-form" class="login-form" action= "<?php echo $current_page;?>" method="post">
<div class="header">
<h1>Login Form</h1>
<span>Fill out the form below to login to my super awesome imaginary control panel.</span>
</div>
<div class="content">
<input name="username" type="text" class="input username" placeholder="Username" />
<div class="user-icon"></div>
<input name="password" type="password" class="input password" placeholder="Password" />
<div class="pass-icon"></div>
</div>
<div class="footer">
<input type="submit" name="button" value="submit" class="button" />
<a href="../qmc-reg/reg.php" style="color:#000" > Register</a>
</div>
</form>
<?php
if (isset($_POST['username']) && isset($_POST['password'])){
$username = $_POST['username'];
$password = $_POST['password'];
$query_one = "SELECT * ";
$query_one .= "FROM users ";
$query_one .= "WHERE user_name = '".$username."' ";
$query_one .= "AND user_pass = '".$password."' ";
$query_one .= "LIMIT 1";
$result = mysql_query($query_one) or die(mysql_error());
$count = mysql_num_rows($result);
if ($count == 1){
$something = mysql_fetch_array($count);
$_SESSION['user_id'] = $something['user_id'];
$_SESSION['user_name'] = $something['user_name'];
header("location: ../cms/cms.php");
}
else{
echo "<div> Invalid Credentials </div>";
}
}
?>
</div>
<div class="gradient"></div>
</body>
</html>
CMS.php
<?php
session_start(); ?>
<!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" />
<link rel="stylesheet" type="text/css" href="style.css" />
<title>QMC Home</title>
</head>
<body>
<?php
$connection = mysql_connect('localhost','root','');
if(!$connection){
die("Database Connection Failed". mysql_error());
}
$select_db = mysql_select_db('hamdard_attendance');
if(!$select_db){
die("Database Connection Failed" . mysql_error());
}
if (isset($_POST['user_name'])){
$username = $_POST['user_name'];
}
?>
<div id="container">
<div id="header">
<h1 style="text-align:left">Quality Management<span class="off"> Cell</span></h1>
</div>
<div id="menu">
<ul>
<li class="menuitem"><a href="cms.php">Home</a></li>
<li class="menuitem"><a href="cms-attendance.php">Attendance</a></li>
<li class="menuitem"><a href="cms-courses.php">Courses</a></li>
<li class="menuitem"><a href="cms-settings.php">Settings</a></li>
</ul>
<a style="text-align:right" href="cms-logout.php">Logout</a>
</div>
</div>
<div id="content">
<div id="content_top"></div>
<div id="content_main">
<p> Welcome <?php echo $_SESSION['user_name'];?> </p>
<?php
$query_three = "SELECT s.stdnt_name, c.course_name FROM students s inner JOIN student_courses sc ON sc.student_id = s.stdnt_rfid_tag INNER JOIN users u ON s.stdnt_name = u.name INNER JOIN courses c ON c.course_id = sc.course_id where u.user_id = '".$username."'";
$result_attendance3 = mysql_query($query_three) or die(mysql_error());
echo "<table border='1': border-color: silver;'>";
echo "<tr>";
echo "<td align='center' width='200'>" . "<h4>"."Student Name" ."</h4>". "</td>";
echo "<td align='center' width='200'>". "<h4>"."Course Name" ."</h4>". "</td>";
echo "</tr>";
echo "</table>";
while($row = mysql_fetch_array($result_attendance3)){
echo "<br />";
//echo "<td align='center' width='200'>".$row['st_classes_attempt'] . "</td>";
echo "<table border='1': border-color: silver;'>";
echo "<tr>";
echo "<td align='center' width='200'>".$row['stdnt_name'] . "</td>";
echo "<td align='center' width='200'>".$row['course_name'] . "</td>";
//echo "<td align='center' width='200'>".$row['st_classes_attempt'] . "</td>";
echo "</tr>";
echo "</table>";
}
?>
<p> </p>
<p> </p>
<div id="content_bottom"></div>
</div>
</div>
</body>
</html>