here is my login.php just a simple to hash the passwords and redirect user upon successful log in.
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$username = mysqli_real_escape_string($db , $_POST['umail']);
$userQuery = "SELECT username, password FROM users WHERE username = '$username'";
$result = mysqli_query($db, $userQuery);
$queryRow = mysqli_fetch_array($result, MYSQLI_ASSOC);
$queryCount = mysqli_num_rows($result);
$verifyPassword = password_verify($_POST['upassword'], $queryRow['password']);
if ($verifyPassword){
$_SESSION['username'] = $username;
header("Location:homeDemo.php");
}else{
echo "Username Or Password is invalid";
}
mysqli_close($db);
}
here is the page the user is reirected to
if (isset($_POST['sendList'])) {
/* $itemName = $_POST['itemName'];
$itemQuantity = $_POST['itemQuantity'];
print_r($itemName);
print_r($itemQuantity);*/
print_r($_SESSION['username']);
$itemList = $_POST['itemList'];
print_r($itemList);
/* foreach($itemName as $key => $iName ){
print_r($iName);
echo " ";
}
foreach($itemQuantity as $key=> $iQuantity){
print_r($iQuantity);
echo " ";
}*/
}
<div class="container">
<form class="col s12" action="" method="POST">
<div class="center-align">
<button type="button" name="button" class="waves-effect #ff3d00 deep-orange accent-3 waves-red btn-large addField">Add a new row</button>
</div>
<table>
<thead>
<tr>
<th class="center-align" data-field="name">Item Name</th>
<th class="center-align" data-field="price">Item Quantity</th>
</tr>
</thead>
<tbody class="listWrapper">
<tr>
<td>
<div class="input-field col s6">
<input type="text" class="validate" name="itemList[]">
</div>
</td>
<td>
<div class="input-field col s6">
<input type="text" class="validate" name="itemList[]">
</div>
</td>
</tr>
<tr>
<td>
<div class="input-field col s6">
<input type="text" class="validate" name="itemList[]">
</div>
</td>
<td>
<div class="input-field col s6">
<input type="text" class="validate" name="itemList[]">
</div>
</td>
</tr>
</tbody>
</table>
<div class="center-btn">
<div class="input-field col s12">
<select class="" name="shopCenters" multiple>
<option value="" disabled select>Select Your Preferred Shopping Center</option>
<option value="Shoprite">Shoprite Accra Mall</option>
<option value="MaxMart">MaxMart Osu</option>
<option value="Marina">Marina Mall</option>
<label for="">Shopping Center</label>
</select>
</div>
<input type="submit" class="btn #ff3d00 deep-orange accent-3 center-align" name="sendList" value="SEND">
</div>
</form>
and my authentication file to prevent users from accessing the homeDemo.php file if not logged in
<?php
if(!isset($_SESSION['username']))
{
session_start();
header('location:Login.php');
exit;
}
?>