Advertisement
Guest User

Untitled

a guest
Dec 6th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.37 KB | None | 0 0
  1.  
  2. <!DOCTYPE>
  3. <html>
  4. <head>
  5. <title>Echobuild</title>
  6. <link rel="stylesheet" href="http://demos.jquerymobile.com/1.4.5/css/themes/default/jquery.mobile-1.4.5.min.css" />
  7. <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile.structure-1.4.5.min.css" />
  8. <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  9. <script src="http://code.jquery.com/mobile/1.4.4/jquery.mobile-1.4.4.js"></script>
  10. </head>
  11.  
  12. <div id="page1" data-role="page">
  13. <div data-role="header">Welcome to Echobuild!</div>
  14.  
  15. <a href="#page2" data-transition="slide" class="ui-btn">Login</a>
  16.  
  17. <a href="#page3" data-transition="slide" class="ui-btn">Register</a>
  18.  
  19. <div data-role="footer">Copyrigth 2016</div>
  20. </div>
  21.  
  22. <div id="page2" data-role="page">
  23. <div data-role="header">Login</div>
  24.  
  25. <?PHP
  26.  
  27. if($_POST){
  28.  
  29. $Username = $_POST['Username'];
  30. $Password = $_POST['Password'];
  31.  
  32. try {
  33. $host = '127.0.0.1';
  34. $dbname = 'echobuild';
  35. $user = 'root';
  36. $pass = '';
  37. # MySQL with PDO_MYSQL
  38. $DBH = new PDO("mysql:host=$host;dbname=$dbname;port=3307", $user, $pass);
  39.  
  40. $sql = "select * from users where Username = ? and Password = ?";
  41. $sth = $DBH->prepare($sql);
  42.  
  43. $sth->bindParam(1,$Username);
  44. $sth->bindParam(2,$Password);
  45. $sth->execute();
  46.  
  47. $check = $sth->fetch(PDO::FETCH_ASSOC);
  48.  
  49. $message = '';
  50. if(!empty($check)){
  51. $Username = $check['Username'];
  52.  
  53. $message = 'Loggin in!';
  54. }else{
  55. $message = 'Sorry, details incorrect';
  56. }
  57.  
  58. if ($sth->rowCount() > 0){
  59.  
  60. $Id = $rec['Id'];
  61. $AccType = $rec['AccType'];
  62.  
  63. if($AccType == 'Customer'){
  64. echo '<script>window.location="page4" </script>';
  65. die;
  66. }
  67. if($AccType == 'Staff'){
  68. echo '<script>window.location="page5" </script>';
  69. die;
  70. }
  71. if($AccType == 'Delivery'){
  72. echo '<script>window.location="page6" </script>';
  73. die;
  74. }
  75. if($AccType == 'Admin'){
  76. echo '<script>window.location="page7" </script>';
  77. die;
  78. }
  79. if($Username||$Password == ''){
  80. echo '<script>alert="Please enter a valid username and password!" </script>';
  81. }
  82. }
  83.  
  84. }catch(PDOException $e) {echo 'Error';}
  85. }
  86.  
  87. ?>
  88. <form method="post" action=" <?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" >
  89.  
  90. <label for="text-1">Username:</label>
  91. <input type="text" name="Username" id="Username" value="">
  92.  
  93. <label for="text-2">Password:</label>
  94. <input type="password" name="Password" id="Password" value="">
  95.  
  96. <input type="submit" value="Login">
  97.  
  98. </form>
  99. </div>
  100.  
  101.  
  102. <div id="page3" data-role="page">
  103. <div data-role="Register">Register Page</div>
  104.  
  105. <?php
  106. if($_POST){
  107.  
  108. $firstname = $_POST['FirstName'];
  109. $lastname = $_POST['LastName'];
  110. $address = $_POST['Address'];
  111. $phone = $_POST['Phone'];
  112. $acctype = $_POST['AccType'];
  113. $email = $_POST['Email'];
  114. $username = $_POST['Username'];
  115. $password = $_POST['Password'];
  116. $password1 = $_POST['Password1'];
  117.  
  118. try {
  119. $host = '127.0.0.1';
  120. $dbname = 'echobuild';
  121. $user = 'root';
  122. $pass = '';
  123. # MySQL with PDO_MYSQL
  124. $DBH = new PDO("mysql:host=$host;dbname=$dbname;port=3307", $user, $pass);
  125.  
  126. $sql = "INSERT INTO `Users` (`FirstName`, `LastName`, `Address`, `Phone`, `AccType`, `Email`, `Username`, `Password`, `Password1`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?);";
  127.  
  128. $sth = $DBH->prepare($sql);
  129.  
  130. $sth->bindParam(1, $firstname, PDO::PARAM_INT);
  131. $sth->bindParam(2, $lastname, PDO::PARAM_INT);
  132. $sth->bindParam(3, $address, PDO::PARAM_INT);
  133. $sth->bindParam(4, $phone, PDO::PARAM_INT);
  134. $sth->bindParam(5, $acctype, PDO::PARAM_INT);
  135. $sth->bindParam(6, $email, PDO::PARAM_INT);
  136. $sth->bindParam(7, $username, PDO::PARAM_INT);
  137. $sth->bindParam(8, $password, PDO::PARAM_INT);
  138. $sth->bindParam(9, $password1, PDO::PARAM_INT);
  139.  
  140. $sth->execute();
  141.  
  142. }catch(PDOException $e) {echo 'Error';}
  143. echo '<script>alert="You are now register!" </script>';
  144.  
  145. }
  146.  
  147. ?>
  148. <form method="post" action=" <?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>" >
  149. <label for="text-3">First Name:</label>
  150. <input type="text" data-clear-btn="true" name="FirstName" id="FirstName" value="">
  151.  
  152. <label for="text-4">Last Name:</label>
  153. <input type="text" data-clear-btn="true" name="LastName" id="LastName" value="">
  154.  
  155. <label for="text-5">Address:</label>
  156. <input type="text" data-clear-btn="true" name="Address" id="Address" value="">
  157.  
  158. <label for="text-6">Phone:</label>
  159. <input type="text" data-clear-btn="true" name="Phone" id="Phone" value="">
  160.  
  161. <label for="text-7">Account Type:</label>
  162. <input type="text" data-clear-btn="true" name="AccType" id="AccType" value="">
  163.  
  164. <label for="text-8">Email:</label>
  165. <input type="text" data-clear-btn="true" name="Email" id="Email" value="">
  166.  
  167. <label for="text-9">Username:</label>
  168. <input type="text" data-clear-btn="true" name="Username" id="Username" value="">
  169.  
  170. <label for="text-10">Password:</label>
  171. <input type="password" data-clear-btn="true" name="Password" id="Password" value="">
  172.  
  173. <label for="text-11">Confirm Password:</label>
  174. <input type="password" data-clear-btn="true" name="Password1" id="Password1" value="">
  175.  
  176. <input type="submit" name="submit" value="Register" class="ui-btn ui-corner-all">
  177.  
  178. </form>
  179. </div>
  180.  
  181. <div id="page4" data-role="page">
  182. <div data-role="Customer">Customer Page</div>
  183.  
  184. <?php
  185. session_start();
  186.  
  187. $_SESSION['Username'] = '';
  188.  
  189. echo 'You are logged!' . session_id();
  190. ?>
  191. <a href="#page8" data-transition="slide" class="ui-btn">Logout</a>
  192.  
  193.  
  194. </div>
  195.  
  196. <div id="page5" data-role="page">
  197. <div data-role="Staff">Staff Page</div>
  198.  
  199. <?php
  200. session_start();
  201.  
  202. $_SESSION['Username'] = '';
  203.  
  204. echo 'You are logged!' . session_id();
  205. ?>
  206. <a href="#page8" data-transition="slide" class="ui-btn">Logout</a>
  207.  
  208. </div>
  209.  
  210. <div id="page6" data-role="page">
  211. <div data-role="Delivery">Delivery Page</div>
  212.  
  213. <?php
  214. session_start();
  215.  
  216. $_SESSION['Username'] = '';
  217.  
  218. echo 'You are logged!' . session_id();
  219. ?>
  220. <a href="#page8" data-transition="slide" class="ui-btn">Logout</a>
  221.  
  222. </div>
  223.  
  224. <div id="page7" data-role="page">
  225. <div data-role="Admin">Admin Page</div>
  226.  
  227. <?php
  228. session_start();
  229.  
  230. $_SESSION['Username'] = '';
  231.  
  232. echo 'You are logged!' . session_id();
  233. ?>
  234. <a href="#page8" data-transition="slide" class="ui-btn">Logout</a>
  235.  
  236. </div>
  237.  
  238. <div id="page8" data-role="page">
  239. <div data-role="Logout">Logout Page</div>
  240.  
  241. <?php
  242. session_start();
  243.  
  244. if(session_destroy()){
  245. header("Location: main.php");
  246. }
  247. ?>
  248.  
  249.  
  250. </div>
  251.  
  252.  
  253.  
  254.  
  255. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement