Good Afternoon everyone,
I am having some problems recreating an app from a book im reading, I was hoping someone might be kind enough to advise me. The userid and password is stored in an admin table in mysql under the auctions database;
When the user logs in the sidebar and nav are supposed to be displayed; when an incorrect login is entered it is supposed to echo “incorrect login” and allow the user to try to authenticate again.
The problem im having is that it seems to be working when an incorrect user name and password is entered however when i enter a correct user and password it simply reloads the page without any error message but does not display the side Nav . which leads me to believe that its working somehow?
validate.inc.php
<?php
$userid= $_POST['userid'];
$password= $_POST['password'];
$query= "SELECT name FROM admins WHERE userid=? AND password= SHA2(?, 256)";
$db= new mysqli("localhost", "ah_user", "AuctionHelper", "auction");
$stmt= $db->prepare($query);
$stmt->bind_param("ss", $userid, $password);
$stmt->execute();
$stmt->bind_result($name);
$stmt->fetch();
if (isset ($name)){
echo "<h2> welcome to auction helper</h2>\n";
$_SESSION['login']= $name;
header("Location: index.php");
} else {
echo "<h2> sorry Login incorrect </h2>\n";
echo "<a href=\"index.php\"> Please try again </a>\n";
}
?>
nav.inc.php
<table width="100%" cellpadding="3">
<tr>
<?php
if (!isset($_SESSION['login']))
echo "<td></td> \n";
else {
echo "<td><h3>Welcome, {$_SESSION['login']}</h3>
</td> \n";
?>
</tr>
<tr>
<td><a href="index.php"><strong> Home </strong></a></td>
</tr>
<tr>
<td><strong>Bidders</strong></td>
</tr>
<tr>
<td> <a href="index.php?content=listbidders">
<strong>List Bidders</strong></a></td>
</tr>
<tr>
<td> <a href="index.php?content=newbidder">
<strong>Add New Bidder</strong></a></td>
</tr>
<tr>
<td><strong> Items</strong></td>
</tr>
<tr>
<td> <a href="index.php?content=listitems"> <strong>List Items</strong></a></td>
</tr>
<tr>
<td> <a href="index.php?content=newitem">
<strong>Add New Item</strong></a></td>
</tr>
<tr><td><hr></td></tr>
<tr><td><a href="index.php?content=logout"> <strong>Logout</strong></a></td></tr>
<tr>
<td> </td>
</tr>
<tr>
<td>
<form action="index.php" method="post">
<label>Search for item: </label><br>
<input type="text" name="itemid" size="14"/>
<input type="submit" value="find"/>
<input type="hidden" name="content" value="updateitem">
</form>
</td> </tr>
<tr>
<td>
<form action="index.php" method="post">
<label>Search for bidder: </label><br>
<input type="text" name="bidderid" size="14"/>
<input type="submit" value="find"/>
<input type="hidden" name="content" value="displaybidder">
</form>
</td> </tr>
<?php
}
?>
</table>
main.inc.php
<?php
if (!isset($_SESSION['login'])) {
?>
<h2>Please log in</h2><br>
<form name="login" action="index.php" method="post"> <label>User ID</label>
<input type="text" name="userid" size="10">
<br>
<br>
<label>Password</label>
<input type="password" name="password" size="10">
<br>
<br>
<input type="submit" value="Login">
<input type="hidden" name="content" value="validate"> </form>
<?php
} else {
echo "<h2> Welcome to AuctionHelper</h2> \n";
echo "<br> <br> \n";
echo "<p>This program tracks bidder and auction item information</p> \n";
echo "<p>Please use the links in the navigation window</p> \n";
echo "<p>Please DO NOT use the browser navigation buttons!</p>\n";
}
?>
<script language="javascript">
document.login.userid.focus();
document.login.userid.select();
</script>
index.php
<php
session_start();
include("bidder.php");
include("item.php");
?>
<!DOCTYPE html>
<html>
<head>
<title>AuctionHelper </title>
<link rel="stylesheet" type="text/css" href="ah_styles.css">
</head>
<body>
<header>
<?php include("header.inc.php"); ?>
</header>
<section id="container">
<nav>
<?php include("nav.inc.php"); ?>
</nav>
<main>
<?php
if (isset($_REQUEST['content'])) {
include($_REQUEST['content'] . ".inc.php");
} else {
include("main.inc.php");
}
?>
</main>
<aside>
<?php include ("aside.inc.php"); ?>
</aside>
</section>
<footer>
<?php include("footer.inc.php"); ?>
</footer>
</body>
</html>
admin table in auction database
MariaDB [auction]> SELECT * FROM admins;
+--------+-----------+------------------------------------------------------------------+
| userid | name | password |
+--------+-----------+------------------------------------------------------------------+
| rich | rich blum | 3cdfa761361762ddedc01ea1428db10a92e327325f490f7f34f1b1b91d994f22 |
+--------+-----------+------------------------------------------------------------------+
1 row in set (0.00 sec)
if you guys wanna see the include files for bidder.php and item.php i can post those as well, but im thinking its not related to the problem.