Guest User

Untitled

a guest
Nov 13th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.36 KB | None | 0 0
  1. index5.php
  2. <html>
  3. <head>
  4. </head>
  5. <body>
  6.  
  7.  
  8. <?php
  9. if(isset($_GET['success']))
  10. {
  11. echo "updated";
  12. }
  13. if(isset($_GET['delete']))
  14. {
  15. echo "deleted";
  16. }
  17. include('db.php');
  18. $query=$db->query("select * from form1");
  19. $result=$query->fetchAll();
  20. ?>
  21. <form method="POST" action="edit5.php" >
  22. <table border='1'>
  23. <tr>
  24. <td>name</td>
  25. <td>address</td>
  26. <td>phoneno</td>
  27. <td>gender</td>
  28. <td>state</td>
  29. <td>country</td>
  30. <td>action</td>
  31.  
  32. </tr>
  33. <?php
  34. foreach($result as $row)
  35. {
  36. ?>
  37. <tr><td><?php echo $row['name'];?></td>
  38. <td><?php echo $row['address'];?></td>
  39. <td><?php echo $row['phone_no'];?></td>
  40. <td><?php echo $row['gender'];?></td>
  41. <td><?php echo $row['state'];?></td>
  42. <td><?php echo $row['country'];?></td>
  43. <td><a href="edit5.php?id=<?php echo $row['id'];?>">Edit</a> <a href="delete5.php?id=<?php echo $row['id'];?>">Delete</a> </td>
  44.  
  45. </tr>
  46. <?php } ?>
  47. </table>
  48. </form>
  49. </body>
  50. </html>
  51. edit5,php
  52. <html>
  53. <head>
  54. </head>
  55. <body>
  56. <?php
  57. include('db.php');
  58. $id=$_GET['id'];
  59. $query=$db->query("select * from form1 where id=$id");
  60. $row=$query->fetch(PDO::FETCH_ASSOC);
  61. ?>
  62. <form method="POST">
  63. <table border='1'>
  64. <tr>
  65. <td>Name</td>
  66. <td><input type="text" name="name" value="<?php echo $row['name'];?>"></td>
  67. </tr>
  68. <tr>
  69. <td>Address</td>
  70. <td><textarea name="address" rows="10" cols="5" ><?php echo $row['address'];?></textarea></td>
  71. </tr>
  72. <tr>
  73. <td>Phone</td>
  74. <td><input type="text" name="phone" value="<?php echo $row['phone_no'];?>"></td>
  75. </tr>
  76. </tr>
  77. <tr>
  78. <td>Gender</td>
  79. <td>
  80. Male:<input type="radio" name="r1" value="male">
  81. Female:<input type="radio" name="r1" value="female">
  82. </td></tr>
  83. <tr>
  84. <td>State</td>
  85. <td><select name="state">;
  86. <option value="kerala">Kerala</option>
  87. <option value="Tamilnadu">Tamilnadu</option>
  88. </select>
  89. </td></tr>
  90. <tr>
  91. <td>Country</td>
  92. <td><select name="country">
  93. <option value="India">India</option>
  94. <option value="Pak">Pak</option>
  95. </select>
  96. </td></tr>
  97. <td><input type="submit" name="submit" value="update"></td>
  98. <td><input type="hidden" name="id" value="<?php echo $row['id'];?>">
  99. </tr>
  100.  
  101. </form>
  102. </table>
  103. </body>
  104. </html>
  105. <?php
  106. include('db.php');
  107. if(isset($_POST['submit']))
  108. {
  109. $name=$_POST['name'];
  110. $phone=$_POST['phone'];
  111. $address=$_POST['address'];
  112. $gender=$_POST['r1'];
  113. $state=$_POST['state'];
  114. $country=$_POST['country'];
  115. $id=$_POST['id'];
  116. $query=$db->query("update form1 set name='$name',address='$address',phone_no='$phone',gender='$gender',state='$state',country='$country' where id='$id'");
  117. if($query==true)
  118. {
  119. header("location:index5.php?success=1");
  120. }
  121. else
  122. {
  123. echo "fail";
  124. }
  125. }
  126. ?>
  127.  
  128. delete5.php
  129. <?php
  130. include('db.php');
  131. $id=$_GET['id'];
  132. $query=$db->query("delete from form1 where id=$id");
  133. if($query==true)
  134. {
  135. header("location:index5.php?delete");
  136. }
  137. else
  138. {
  139. echo "false";
  140. }
  141. ?>
  142. test1.php
  143. <html>
  144. <head></head>
  145. <body>
  146. <form method="POST" >
  147. <table border='1'>
  148. <tr>
  149. <td>Username<input type="text" name="username"</td>
  150. <td>Password<input type="text" name="password"</td>
  151. <td>Course</td>
  152. <td>Php<input type="checkbox" name="course" value="php"></td>
  153. <td>java<input type="checkbox" name="course" value="java"></td>
  154. <td><input type="submit" name="submit" value="submit"></td>
  155. </tr>
  156. </table>
  157. </form>
  158. </body>
  159. </html>
  160. <?php
  161. include('db.php');
  162. if(isset($_POST['submit']))
  163. {
  164. $username=$_POST['username'];
  165. $password=$_POST['password'];
  166. $course=$_POST['course'];
  167. $query=$db->query("insert into form2(username,password,course)values('$username','$password','$course')");
  168. }
  169. ?>
  170. index2.php
  171. <html>
  172. <head>
  173. </head>
  174. <body>
  175. <form method="POST">
  176. Name: <input type="text" name="name">
  177. Address: <textarea name="address" cols="10" rows="5"></textarea>
  178. Phone no: <input type="text" name="phoneno">
  179. Male<input type="radio" name="r1" value="male">
  180. Female<input type="radio" name="r1" value="female">
  181. Country: <select name="country">
  182. <option value="India">India</option>
  183. <option value="pak">Pak</option>
  184. </select>
  185. State: <select name="state">
  186. <option value="Kerala">Kerala</option>
  187. <option value="Tamilnadu">Tamilnadu</option>
  188. </select>
  189. <input type="submit" name="submit" value="submit">
  190. </form>
  191. </body>
  192. </html>
  193. <?php
  194. include('db2.php');
  195. if(isset($_POST['submit']))
  196. {
  197. echo $name=$_POST['name'];
  198. echo $address=$_POST['address'];
  199. echo $phoneno=$_POST['phoneno'];
  200. echo $gender=$_POST['r1'];
  201. echo $state=$_POST['state'];
  202. echo $country=$_POST['country'];
  203. $query=$db->query("Insert into form1(name,address,phone_no,gender,state,country) values('$name','$address','$phoneno','$gender','$state','$country')");
  204. if($query==true)
  205. {
  206. echo "success";
  207. }
  208. else
  209. {
  210. echo "fail";
  211. }
  212. }
  213. ?>
  214. db.php
  215. <?php
  216. $dsn="mysql:host=localhost;dbname=register";
  217. $username="root";
  218. $password="";
  219. $db=new PDO($dsn,$username,$password);
  220. ?>
  221. editable.php
  222. <html>
  223. <head>
  224. </head>
  225. <body>
  226. <?php
  227. include('db.php');
  228. $query=$db->query("select * from form where id=1");
  229. $result=$query->fetchAll();
  230. ?>
  231. <form action="edit.php" method="POST">
  232. <table border='1'>
  233. <tr><td>name</td>
  234. <td>address</td>
  235. <td>phoneno</td>
  236. <td>action</td>
  237. </tr>
  238. <?php
  239. foreach($result as $row)
  240. {
  241. ?>
  242. <tr><td><?php echo $row['name'];?></td>
  243. <td><?php echo $row['address'];?></td>
  244. <td><?php echo $row['phone_no'];?></td>
  245. <td><input type="submit" name ="edit" value="edit"></td>
  246. </tr>
  247. <?php } ?>
  248. </table>
  249. </form>
  250. </body>
  251. </html>
Add Comment
Please, Sign In to add comment