Advertisement
Guest User

Untitled

a guest
Nov 25th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.60 KB | None | 0 0
  1. <html>
  2.  
  3. <head>
  4. <title>Add New Record</title>
  5. </head>
  6.  
  7. <body>
  8. <?php
  9. if(isset($_POST['add'])) {
  10. $dbhost = 'localhost';
  11. $dbuser = 'root';
  12. $dbpass = '';
  13. $db = 'school';
  14. $conn = mysql_connect($dbhost, $dbuser, $dbpass, $db);
  15.  
  16. if(! $conn ) {
  17. die('Could not connect: ' . mysql_error());
  18. }
  19.  
  20. if(! get_magic_quotes_gpc() ) {
  21. $Town = addslashes ($_POST['Town']);
  22. $Unit = addslashes ($_POST['Unit']);
  23. $Street = addslashes ($_POST['Street']);
  24. $Name = addslashes ($_POST['Name']);
  25. $Surname = addslashes ($_POST['Surname']);
  26. $Tel = addslashes ($_POST['Tel']);
  27. $Males = addslashes ($_POST['Males']);
  28. $Females = addslashes ($_POST['Females']);
  29. $Children = addslashes ($_POST['Children']);
  30. }else {
  31. $Town = $_POST['Town'];
  32. $Unit = $_POST['Unit'];
  33. $Street = $_POST['Street'];
  34. $Name = $_POST['Name'];
  35. $Surname = $_POST['Surname'];
  36. $Tel = $_POST['Tel'];
  37. $Males = $_POST['Males'];
  38. $Females = $_POST['Females'];
  39. $Children = $_POST['Children'];
  40.  
  41.  
  42. }
  43.  
  44.  
  45. $sql = "INSERT INTO masjid ". "(id,town,unit,street,name,surname,tel,males,females,children,dtAdd) ". "VALUES('','$Town','$Unit','$Street','$Name','$Surname','$Tel','$Males','$Females','$Children',now())";
  46.  
  47.  
  48. mysql_select_db($db);
  49. $retval = mysql_query( $sql, $conn );
  50.  
  51. if(! $retval ) {
  52. die('Could not enter data: ' . mysql_error());
  53. }
  54.  
  55. echo "Entered data successfully\n";
  56. echo $sql;
  57. mysql_close($conn);
  58.  
  59. }else {
  60.  
  61. }
  62. ?>
  63. <form method = "post" action = "<?php $_PHP_SELF ?>">
  64. <table width = "400" border = "0" cellspacing = "1"
  65. cellpadding = "2">
  66.  
  67. <tr>
  68. <td width = "100">Town</td>
  69. <!--The code for musa -->
  70. <td>
  71. <?php
  72. # I am connecting to the database again because the codes used above they
  73. # are no more suported by php so this is the best way so far
  74. # Dont forget to change the dbname school to yourown and root plus blunk password
  75. $conn = new PDO ('mysql:host=localhost;dbname=school','root','');
  76. if($conn){
  77. //echo "connected";
  78. }
  79. else{
  80. // echo "Musa db not connected ";
  81. }
  82. # Fechinh data from the table town
  83. $sqlTown = "SELECT tname FROM town";
  84. $mytown = $conn->prepare($sqlTown);
  85. $mytown->execute();
  86. echo "<select name='tname'>";
  87. while ($row =$mytown->fetch(PDO::FETCH_ASSOC)){
  88. echo "<option value='" . $row['tname'] . "'>" . $row['tname'] . "</option>";
  89.  
  90. }
  91. echo "</select>";?>
  92.  
  93. </td>
  94.  
  95. <!--Codes for musa ends-->
  96. </tr>
  97.  
  98. <tr>
  99. <td width = "100">Unit</td>
  100. <td><input name = "Unit" type = "text"
  101. id = "Unit"></td>
  102. </tr>
  103. <tr>
  104. <td width = "100">Street</td>
  105. <td><input name = "Street" type = "text"
  106. id = "Street"></td>
  107. </tr>
  108. <tr>
  109. <td width = "100">Name</td>
  110. <td><input name = "Name" type = "text"
  111. id = "Name"></td>
  112. </tr>
  113. <tr>
  114. <td width = "100">Surname</td>
  115. <td><input name = "Surname" type = "text"
  116. id = "Surname"></td>
  117. </tr>
  118. <tr>
  119. <td width = "100">Tel</td>
  120. <td><input name = "Tel" type = "text"
  121. id = "Tel"></td>
  122. </tr>
  123. <tr>
  124. <td width = "100">Males</td>
  125. <td><input name = "Males" type = "text"
  126. id = "Males"></td>
  127. </tr>
  128. <tr>
  129. <td width = "100">Females</td>
  130. <td><input name = "Females" type = "text"
  131. id = "Females"></td>
  132. </tr><tr>
  133. <td width = "100">Children</td>
  134. <td><input name = "Chilren" type = "text"
  135. id = "Children"></td>
  136. </tr>
  137.  
  138.  
  139. <tr>
  140. <td width = "100"> </td>
  141. <td> </td>
  142. </tr>
  143.  
  144. <tr>
  145. <td width = "100"> </td>
  146. <td>
  147. <input name = "add" type = "submit" id = "add"
  148. value = "Add">
  149. </td>
  150. </tr>
  151.  
  152. </table>
  153. </form>
  154.  
  155.  
  156.  
  157. </body>
  158. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement