Advertisement
Guest User

Untitled

a guest
Sep 5th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.51 KB | None | 0 0
  1. <?php
  2. $databaseHost = 'localhost';
  3. $databaseName = 'test';
  4. $databaseUsername = 'root';
  5. $databasePassword = '';
  6. $mysqli = mysqli_connect($databaseHost, $databaseUsername, $databasePassword, $databaseName);
  7. ?>
  8.  
  9. <?php
  10. include_once("config.php");
  11. $result = mysqli_query($mysqli, "SELECT * FROM users ORDER BY id DESC");
  12. ?>
  13.  
  14. <html>
  15. <head>
  16. <title>Registration</title>
  17. </head>
  18. <body>
  19. <table width='50%' border=0>
  20.  
  21. <tr bgcolor='yellow'>
  22. <td><a href="index.php">Dashboard</a></td>
  23. <td><a href="reg1.php">Registration Stage-1</a></td>
  24. <td><a href="reg2.php">Registration Stage-2</a></td>
  25. <td><a href="reg3.php">Registration Stage-3</a></td>
  26. <td><a href="view.php">View Report</a></td>
  27. </tr>
  28. <table width='50%' border=0>
  29. <tr bgcolor='#CCCCCC'>
  30. <td>ID#</td>
  31. <td>Name</td>
  32. <td>Age</td>
  33. <td>Email</td>
  34. <td>Mobile</td>
  35. <td>Change</td>
  36. </br></br>
  37. </tr>
  38. <?php
  39. while($res = mysqli_fetch_array($result)) {
  40. echo "<tr>";
  41. echo "<td>".$res['id']."</td>";
  42. echo "<td>".$res['name']."</td>";
  43. echo "<td>".$res['age']."</td>";
  44. echo "<td>".$res['email']."</td>";
  45. echo "<td>".$res['mobile']."</td>";
  46. echo "<td><a href="edit.php?id=$res[id]">Change</a></td>";
  47. }
  48. ?>
  49. </table>
  50. </body>
  51. </html>
  52.  
  53. <?php
  54. include_once("config.php");
  55. if(isset($_POST['update']))
  56. {
  57. $id = mysqli_real_escape_string($mysqli, $_POST['id']);
  58. $name = mysqli_real_escape_string($mysqli, $_POST['name']);
  59. $age = mysqli_real_escape_string($mysqli, $_POST['age']);
  60. $email = mysqli_real_escape_string($mysqli, $_POST['email']);
  61. $mobile = mysqli_real_escape_string($mysqli, $_POST['mobile']);
  62.  
  63. if(empty($name) || empty($age) || empty($email) || empty($mobile)) {
  64. if(empty($name)) {
  65. echo "<font color='red'>Name field is empty.</font><br/>";
  66. }
  67. if(empty($age)) {
  68. echo "<font color='red'>Age field is empty.</font><br/>";
  69. }
  70. if(empty($email)) {
  71. echo "<font color='red'>Email field is empty.</font><br/>";
  72. }
  73. if(empty($mobile)) {
  74. echo "<font color='red'>Mobile field is empty.</font><br/>";
  75. }
  76. } else {
  77. $result = mysqli_query($mysqli, "UPDATE users SET name='$name',age='$age',email='$email',mobile='$mobile' WHERE id=$id");
  78. header("Location: index.php");
  79. }
  80. }
  81. ?>
  82. <?php
  83. $id = $_GET['id'];
  84. $result = mysqli_query($mysqli, "SELECT * FROM users WHERE id=$id");
  85.  
  86. while($res = mysqli_fetch_array($result))
  87. {
  88. $name = $res['name'];
  89. $age = $res['age'];
  90. $email = $res['email'];
  91. $mobile = $res['mobile'];
  92. }
  93. ?>
  94. <html>
  95. <head>
  96. <title>Change Registration Data</title>
  97. </head>
  98.  
  99. <body>
  100. <table width='50%' border=0>
  101.  
  102. <tr bgcolor='yellow'>
  103. <td><a href="index.php">Dashboard</a></td>
  104. <td><a href="reg1.php">Registration Stage-1</a></td>
  105. <td><a href="reg2.php">Registration Stage-2</a></td>
  106. <td><a href="reg3.php">Registration Stage-3</a></td>
  107. <td><a href="view.php">View Report</a></td>
  108. </tr>
  109. <form name="form1" method="post" action="edit.php">
  110. <table border="0">
  111. <tr>
  112. <td>Name</td>
  113. <td><input type="text" name="name" value="<?php echo $name;?>"></td>
  114. </tr>
  115. <tr>
  116. <td>Age</td>
  117. <td><input type="text" name="age" value="<?php echo $age;?>"></td>
  118. </tr>
  119. <tr>
  120. <td>Email</td>
  121. <td><input type="text" name="email" value="<?php echo $email;?>"></td>
  122. </tr>
  123. <tr>
  124. <td>Mobile</td>
  125. <td><input type="text" name="mobile" value="<?php echo $mobile;?>"></td>
  126. </tr>
  127. <tr>
  128. <td><input type="hidden" name="id" value=<?php echo $_GET['id'];?>></td>
  129. <td><input type="submit" name="update" value="Update"></td>
  130. </tr>
  131. </table>
  132.  
  133. </form>
  134. <table width='50%' border=0>
  135.  
  136. <tr bgcolor='#CCCCCC'>
  137. <td>Name</td>
  138. <td>Age</td>
  139. <td>Email</td>
  140. <td>Mobile</td>
  141. </tr>
  142. <?php
  143. $result = mysqli_query($mysqli, "SELECT * FROM users ORDER BY id DESC"); // using mysqli_query instead
  144. while($res = mysqli_fetch_array($result)) {
  145. echo "<tr>";
  146. echo "<td>".$res['name']."</td>";
  147. echo "<td>".$res['age']."</td>";
  148. echo "<td>".$res['email']."</td>";
  149. echo "<td>".$res['mobile']."</td>";
  150. }
  151. ?>
  152. </table>
  153. </body>
  154. </html>
  155.  
  156. <html>
  157. <head>
  158. <title>Registration Stage-1</title>
  159. </head>
  160. <body>
  161. <?php
  162. include_once("config.php");
  163.  
  164. if(isset($_POST['Submit'])) {
  165. $name = mysqli_real_escape_string($mysqli, $_POST['name']);
  166. $age = mysqli_real_escape_string($mysqli, $_POST['age']);
  167. $email = mysqli_real_escape_string($mysqli, $_POST['email']);
  168. $mobile = mysqli_real_escape_string($mysqli, $_POST['mobile']);
  169.  
  170. if(empty($name) || empty($age) || empty($email)) {
  171.  
  172. if(empty($name)) {
  173. echo "<font color='red'>Name field is empty.</font><br/>";
  174. }
  175.  
  176. if(empty($age)) {
  177. echo "<font color='red'>Age field is empty.</font><br/>";
  178. }
  179.  
  180. if(empty($email)) {
  181. echo "<font color='red'>Email field is empty.</font><br/>";
  182. }
  183.  
  184. if(empty($mobile)) {
  185. echo "<font color='red'>Mobile field is empty.</font><br/>";
  186. }
  187.  
  188. echo "<br/><a href='javascript:self.history.back();'>Go Back</a>";
  189. } else {
  190.  
  191. $result = mysqli_query($mysqli, "INSERT INTO users(name,age,email,mobile) VALUES('$name','$age','$email','$mobile')");
  192.  
  193. echo "<font color='green'>Data added successfully.";
  194. echo "<br/><a href='index.php'>View Result</a>";
  195. }
  196. }
  197. ?>
  198.  
  199. <html>
  200. <head>
  201. <title>Registration Stage-1</title>
  202. </head>
  203. <body>
  204. <table width='50%' border=0>
  205. <tr bgcolor='yellow'>
  206. <td><a href="index.php">Dashboard</a></td>
  207. <td><a href="reg1.php">Registration Stage-1</a></td>
  208. <td><a href="reg2.php">Registration Stage-2</a></td>
  209. <td><a href="reg3.php">Registration Stage-3</a></td>
  210. <td><a href="view.php">View Report</a></td>
  211. </tr>
  212.  
  213. <form action="reg1.php" method="post" name="form1">
  214. <table width="25%" border="0">
  215. <tr>
  216. <td>Name</td>
  217. <td><input type="text" name="name"></td>
  218. </tr>
  219. <tr>
  220. <td>Age</td>
  221. <td><input type="text" name="age"></td>
  222. </tr>
  223. <tr>
  224. <td>Email</td>
  225. <td><input type="text" name="email"></td>
  226. </tr>
  227. <tr>
  228. <td>Mobile</td>
  229. <td><input type="text" name="mobile"></td>
  230. </tr>
  231. <tr>
  232. <td></td>
  233. <td><input type="submit" name="Submit" value="Add"></td>
  234. </tr>
  235. </table>
  236. </br></br>
  237. </form>
  238. <table width='50%' border=0>
  239. <tr bgcolor='#CCCCCC'>
  240. <td>Name</td>
  241. <td>Age</td>
  242. <td>Email</td>
  243. <td>Mobile</td>
  244. </tr>
  245. <?php
  246. $result = mysqli_query($mysqli, "SELECT * FROM users ORDER BY id DESC"); // using mysqli_query instead
  247. while($res = mysqli_fetch_array($result)) {
  248. echo "<tr>";
  249. echo "<td>".$res['name']."</td>";
  250. echo "<td>".$res['age']."</td>";
  251. echo "<td>".$res['email']."</td>";
  252. echo "<td>".$res['mobile']."</td>";
  253. }
  254. ?>
  255. </table>
  256. </body>
  257. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement