When I log into my networks homepage it is not working. I have connected to the database and can create new users however when I log in I am getting the else statement that shows my session is not working. (It was redirecting back to log in but for learning purposes I set it to echo).
Below is my log in code and homepage code (basic structure). I know it is not secure yet I am still getting to the security part I just need to figure out why this error is happening.
<?php require ("insert.php"); ?>
<?php
if(isset($_POST[ 'Login' ]))
{
session_start();
$email= mysqli_real_escape_string($con, $_POST ['email']);
$pswrd= mysqli_real_escape_string($con, $_POST ['pswrd']);
$result = $con->query(" select * from users where email='$email' AND pswrd='$pswrd' ");
$row = $result->fetch_array(MYSQLI_BOTH);
$_SESSION["UserID"] = $row['User_ID'];
header ('Location: home.php');
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>AMSadler login</title>
<meta charset="utf-8">
<meta name="description" content="description of webpage">
<meta name="keywords" content="keywords go here">
<meta name="author" content="Anthony">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/login.css">
<link rel="index" href="index.php">
<link rel="icon" href="img/favicon.png" sizes="16x16" type="image/png">
</head>
<body>
<div class="header">
<div id="logo">
<a href="index.html"><img src="img/logo.png" alt="logo" title="AMSadler.com"/></a>
</div>
<div id="signup">
<button type="button"><a href="signup.php">Sign up</a></button>
</div>
</div>
<div id="login">
<form method="post" action="home.php">
<input type="text" name="email" placeholder="Email address">
<br>
<input type="password" name="pswrd" placeholder="Password">
<br>
<input id="Login" type="submit" name="Login" value="Login">
</form>
</div>
<footer>
<div id="copyright">
<p>© Copyright 2015</p>
</div>
</footer>
</body>
</html>
<?php require ("insert.php");
session_start();
if (isset($_SESSION ["UserID"] ) ) {
}
else {
echo "not fixed";
// header ('Location: login.php');
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>AMSadler</title>
<meta charset="utf-8">
<meta name="description" content="description of webpage">
<meta name="keywords" content="keywords go here">
<meta name="author" content="Anthony">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/home.css">
<link rel="icon" href="img/favicon.png" sizes="16x16" type="image/png">
</head>
<body>
<div class="header">
<div id="logo">
<a href="index.html"><img src="img/logo.png" alt="logo" title="AMSadler.com"/></a>
</div>
<div id="headertop">
<div id="pagetitle">
<a href="home.php">HOME</a>
</div>
<div id="pagetitle2">
<a href="profile.php">PROFILE</a>
</div>
<div id="pagetitle3">
<h4>Welcome:<?php echo $_SESSION["UserID"];?>to your page</h4>
</div>
</div>
</div>
<div class="wrapper">
<div class="leftsidebar">
<ul>
<li><a href="home.php">Social</a></li>
<li><a href="#">jhbjhbjhb</a></li>
<li><a href="#">jhbbjhb</a></li>
<li><a href="#">jhbbjhbj</a></li>
<li><a href="#">jhbhjbjhb</a></li>
<li><a href="#">bjhbjhb</a></li>
<li><a href="#">rege</a></li>
<li><a href="#">rgerger</a></li>
<li><a href="#">dfbrtbr</a></li>
<li><a href="#">sdvdfgbd</a></li>
</ul>
</div>
<div class="main">
<div id="maintop">
<div id="textboxwrap">
<textarea name="text" id="styled"rows="5" cols="80" placeholder="Write something here.">
</textarea>
</div>
<div id="postbutton">
<input type="submit" name="post" value="Post" />
</div>
</div>
<div id="mainbottom1">
<div ="mainbottomwrap">
Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>
Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>
Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>Your posts will go here.<br>
Your posts will go here.<br>Your posts will go here.<br>
</div>
</div>
</div>
<div class="rightsidebar">
<div id="profilecontainer">
<img src="img/profile.png" alt="Upload a profile pic" title="profile pic" />
</div>
<div id="box">
<a href="#">fgtdhrth</a><br>
<a href="#">dfbrt</a><br>
<a href="#">gverb</a><br>
<a href="#">dsvfe</a><br>
<a href="#">egerg</a><br>
<a href="#">wefgeger</a><br>
<a href="#">rfthrtth</a><br>
<a href="#">gergreg</a>
</div>
</div>
</div>
</body>
</html>