Advertisement
Guest User

Untitled

a guest
Nov 3rd, 2016
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. <?php
  2. include "Functions.php";
  3.  
  4. if (array_key_exists('login_submit', $_POST)) { //check for form submission
  5. $filepath = "./user_data.dat";
  6. $Master_user_array = arrayfile_to_array($filepath); //set array file to variable
  7.  
  8. if (array_key_exists(strtolower($_POST['log_username']), $Master_user_array)) { //checking if login username value = key value in array
  9.  
  10. if ($_POST['log_password'] == $Master_user_array[strtolower($_POST['log_username'])]['password']) { //checking if password matches inputted username
  11. echo "{$_POST['log_username']} logged in."; //posting inputted user log in success & printing invoice table
  12.  
  13. $invoice='Invoice.dat';
  14. //calling array form file
  15. $user_quantity=arrayfile_to_array($invoice);
  16. $inventory='Inventory.dat';
  17. $allproducts= arrayfile_to_array($inventory);
  18.  
  19. echo "<h1>".'Thank you ';
  20. echo $_POST['log_username'];
  21. echo ', for your order!';
  22. echo "</h1>";
  23. echo "<table border=1 cellpadding=3><tr><th colspan=4>Invoice</th></tr>";
  24. echo "<tr><th>Item</th><th>Unit Price</th><th>Quantity</th><th>Extended Price</th></tr>";
  25.  
  26.  
  27. // Now print the invoice, one row at a time
  28. for ($x = 0; $x < count($allproducts); $x++)
  29. {
  30. if ($user_quantity[quantity.$x] != '0'){
  31. echo "<tr>";
  32. echo "<td>" . $allproducts[$x]['Name'] . "</td>";
  33. echo "<td align=right>" ;
  34. printf ("$%.2f", $allproducts[$x]['Price']);
  35. echo "</td>";
  36. echo "<td align=right>" . $user_quantity['quantity'.$x] . "</td>";
  37. $extended = $user_quantity['quantity'.$x] * $allproducts[$x]['Price'];
  38. echo "<td align=right>" ;
  39. printf ("$%.2f", $extended);
  40. echo "</td>";
  41. echo "</tr>";
  42. $total_Ordered += $extended;
  43. }
  44.  
  45. }
  46. echo "<tr><td>Total</td> ";
  47. echo "<td colspan=3 align=right>";
  48. printf ("$%.2f", $total_Ordered);
  49. echo "</td></tr>";
  50. echo "<tr><td>Tax 5.75</td> ";
  51. $tax_Total=.0575*$total_Ordered;
  52. echo "<td colspan=3 align=right>";
  53. printf ("$%.2f", $tax_Total);
  54. echo "</td></tr>";
  55. echo "<tr><td>Shipping</td> ";
  56. $shipping=5;
  57. echo "<td colspan=3 align=right>";
  58. printf ("$%.2f", $shipping);
  59. echo "</td></tr>";
  60. echo "<tr><td><b>Grand Total</td> ";
  61. echo "<td colspan=3 align=right>";
  62. $grand_Total=$total_Ordered+$tax_Total+$shipping;
  63. printf ("$%.2f", $grand_Total);
  64. echo "</td></tr>";
  65. echo "</table>";
  66.  
  67.  
  68. die; //to not print rest of the code
  69. } else {
  70. echo 'wrong password, try again'; //wrong validation error output
  71. }
  72. }
  73. else {
  74. print "User {$_POST['username']} not found. <br>"; //wrong validation error output
  75. }
  76. }
  77.  
  78. if (array_key_exists('create_new_user', $_POST)) { //referring to user creation page if user clicks button
  79. header("Location: Create_New_User.php");
  80. exit;
  81.  
  82. }
  83. ?>
  84. <form action = '<?php echo $_SERVER['PHP_SELF'] ?>' method= 'post'>
  85. Username: <br>
  86. <INPUT TYPE="TEXT" name="log_username" value = "<?php if (isset($_POST['username'])) echo $_POST['username'] ?>"><br>
  87. Password: <br>
  88. <INPUT TYPE="password" name = 'log_password'><br><br>
  89. <INPUT TYPE="SUBMIT" name = 'login_submit' value="Login">
  90. <br>
  91. <INPUT TYPE="SUBMIT" name = 'create_new_user' value="Create New User">
  92. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement