Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- include "Functions.php";
- if (array_key_exists('login_submit', $_POST)) { //check for form submission
- $filepath = "./user_data.dat";
- $Master_user_array = arrayfile_to_array($filepath); //set array file to variable
- if (array_key_exists(strtolower($_POST['log_username']), $Master_user_array)) { //checking if login username value = key value in array
- if ($_POST['log_password'] == $Master_user_array[strtolower($_POST['log_username'])]['password']) { //checking if password matches inputted username
- echo "{$_POST['log_username']} logged in."; //posting inputted user log in success & printing invoice table
- $invoice='Invoice.dat';
- //calling array form file
- $user_quantity=arrayfile_to_array($invoice);
- $inventory='Inventory.dat';
- $allproducts= arrayfile_to_array($inventory);
- echo "<h1>".'Thank you ';
- echo $_POST['log_username'];
- echo ', for your order!';
- echo "</h1>";
- echo "<table border=1 cellpadding=3><tr><th colspan=4>Invoice</th></tr>";
- echo "<tr><th>Item</th><th>Unit Price</th><th>Quantity</th><th>Extended Price</th></tr>";
- // Now print the invoice, one row at a time
- for ($x = 0; $x < count($allproducts); $x++)
- {
- if ($user_quantity[quantity.$x] != '0'){
- echo "<tr>";
- echo "<td>" . $allproducts[$x]['Name'] . "</td>";
- echo "<td align=right>" ;
- printf ("$%.2f", $allproducts[$x]['Price']);
- echo "</td>";
- echo "<td align=right>" . $user_quantity['quantity'.$x] . "</td>";
- $extended = $user_quantity['quantity'.$x] * $allproducts[$x]['Price'];
- echo "<td align=right>" ;
- printf ("$%.2f", $extended);
- echo "</td>";
- echo "</tr>";
- $total_Ordered += $extended;
- }
- }
- echo "<tr><td>Total</td> ";
- echo "<td colspan=3 align=right>";
- printf ("$%.2f", $total_Ordered);
- echo "</td></tr>";
- echo "<tr><td>Tax 5.75</td> ";
- $tax_Total=.0575*$total_Ordered;
- echo "<td colspan=3 align=right>";
- printf ("$%.2f", $tax_Total);
- echo "</td></tr>";
- echo "<tr><td>Shipping</td> ";
- $shipping=5;
- echo "<td colspan=3 align=right>";
- printf ("$%.2f", $shipping);
- echo "</td></tr>";
- echo "<tr><td><b>Grand Total</td> ";
- echo "<td colspan=3 align=right>";
- $grand_Total=$total_Ordered+$tax_Total+$shipping;
- printf ("$%.2f", $grand_Total);
- echo "</td></tr>";
- echo "</table>";
- die; //to not print rest of the code
- } else {
- echo 'wrong password, try again'; //wrong validation error output
- }
- }
- else {
- print "User {$_POST['username']} not found. <br>"; //wrong validation error output
- }
- }
- if (array_key_exists('create_new_user', $_POST)) { //referring to user creation page if user clicks button
- header("Location: Create_New_User.php");
- exit;
- }
- ?>
- <form action = '<?php echo $_SERVER['PHP_SELF'] ?>' method= 'post'>
- Username: <br>
- <INPUT TYPE="TEXT" name="log_username" value = "<?php if (isset($_POST['username'])) echo $_POST['username'] ?>"><br>
- Password: <br>
- <INPUT TYPE="password" name = 'log_password'><br><br>
- <INPUT TYPE="SUBMIT" name = 'login_submit' value="Login">
- <br>
- <INPUT TYPE="SUBMIT" name = 'create_new_user' value="Create New User">
- </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement