Advertisement
Guest User

Untitled

a guest
May 7th, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.33 KB | None | 0 0
  1. <html>
  2. <head>
  3. <link rel="stylesheet" type="text/css" href="style.css"/>
  4. <script src="function.js" type="text/javascript"></script>
  5. </head>
  6.  
  7. <body>
  8. <form name="infoForm" method="post" onsubmit="return checkFields()" action="">
  9. <table>
  10. <tr>
  11. <td>Name:</td>
  12. <td><input type="text" name="name" id="name" maxlength="40"></td>
  13. </tr>
  14. <tr>
  15. <td>Address:</td>
  16. <td><textarea maxlength="45" name="address"id="address" ></textarea></td>
  17. </tr>
  18. <tr>
  19. <td>Phone:</td>
  20. <td><input type="text" name="phone" id="phone" maxlength="20"><br></td>
  21. </tr>
  22. <tr>
  23. <td>Gender:</td>
  24. <td><input checked type="radio" name="gender" id="male" value="Male">Male
  25. <input type="radio" name="gender" id="female" value="Female">Female</td>
  26. </tr>
  27. <tr>
  28. <td>
  29. Nationality:
  30. </td>
  31. <td>
  32. <select name="nation">
  33. <option value="Singapore">Singapore</option>
  34. <option value="Malaysia">Malaysia</option>
  35. <option value="Thailand">Thailand</option>
  36. <option value="Indoensia">Indonesia</option>
  37. <option value="Philippines">Philippines</option>
  38. </select>
  39. </td>
  40. </tr>
  41. <tr>
  42. <td></td>
  43. <td>
  44. <br><input type="reset" value="Cancel">
  45. <input type="submit" name="result" value="Submit" onclick="checkFields()"/>
  46. </td>
  47. </tr>
  48. </table>
  49. </form>
  50.  
  51. <div id="divTable"></div>
  52. </body>
  53. </html>
  54.  
  55. function checkFields(){
  56.  
  57. var name = document.getElementById("name");
  58. var address = document.getElementById("address");
  59. var phone = document.getElementById("Phone");
  60.  
  61. if(confirm('Do you want to submit')){
  62. if(name == null, name == ""||address == null, address == ""||phone == null, phone == ""){
  63. alert("Please fill in all your details.");
  64. return false;
  65. }
  66. else{
  67. var page = "database.php";
  68. var xmlhttp = new XMLHttpRequest();
  69.  
  70. if(xmlhttp==null){
  71. alert("Your browser does not support AJAX!");
  72. return false;
  73. }
  74. xmlhttp.onreadystatechange=function(){
  75. document.getElementById("divTable").innerHTML=xmlhttp.responseText;
  76. }
  77. xmlhttp.open("GET", page, true);
  78. xmlhttp.send(null);
  79. }
  80. }
  81. else{
  82. return false;
  83. }
  84. }
  85.  
  86. <?php
  87. // Define database parameters //
  88. DEFINE ('DB_USER' ,'iqwer222');
  89. DEFINE ('DB_PASSWORD', 'wfwqr');
  90. DEFINE ('DB_HOST', 'localhost');
  91. DEFINE ('DB_NAME', 'aqwfvaqf');
  92.  
  93. $table_info = "info";
  94.  
  95. // Connect to database
  96. $conn = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to Database:'. mysql_error());
  97. @mysql_select_db (DB_NAME) OR die ('Could not select the Database: '.mysql_error());
  98.  
  99. // Delete Row
  100. if(isset($_POST['delete'])){
  101. $id = $_POST['deleteRow'];
  102. $query_string = "delete from $table_info where user_id='$id'";
  103. $result = @mysql_query($query_string);
  104. }
  105.  
  106. //Check if phone no. is duplicate and if not, insert data
  107. if(isset($_POST['result'])){
  108. $phone = $_POST['phone'];
  109. $query_string = "select phone from $table_info where phone='$phone'";
  110. $result = @mysql_query($query_string);
  111. $num_row = mysql_num_rows($result);
  112. if($num_row){
  113. echo "A same phone number has been found. Please enter a different phone number.";
  114. }else{
  115. $query_string = "insert into $table_info(name, address, phone, gender, nation) values('".$_POST['name']."','".$_POST['address']."','".$_POST['phone']."','".$_POST['gender']."','".$_POST['nation']."')";
  116. $result = @mysql_query($query_string);
  117. }
  118. }
  119.  
  120. // Display table
  121. $query_string = "select * from $table_info";
  122. $result = @mysql_query($query_string);
  123. $num_row = mysql_num_rows($result);
  124.  
  125. if($num_row){
  126. echo "<table border=1>";
  127. echo "<tr><th>Name</th><th>Address</th><th>Phone no.</th><th>Gender</th><th>Nationality</th><th>Created</th><th>Modified</th><th>Action</th></tr>";
  128.  
  129. while($row = mysql_fetch_array($result)){
  130. echo "<tr><td>", $row['name'], "</td>";
  131. echo "<td>", $row['address'], "</td>";
  132. echo "<td>", $row['phone'], "</td>";
  133. echo "<td>", $row['gender'], "</td>";
  134. echo "<td>", $row['nation'], "</td>";
  135. echo "<td>", $row['createdTime'], "</td>";
  136. echo "<td>", $row['modifiedTime'], "</td>";
  137. ?>
  138.  
  139. <!--Delete button-->
  140. <td><form id="delete" method="post" action="">
  141. <input type="hidden" name="deleteRow" value="<?php echo $row['user_id'] ?>"/>
  142. <input type="submit" name="delete" value="Delete" onclick="return confirm('Are you sure you want to delete this contact?')"/></td></form></tr>
  143.  
  144. <?php
  145. }
  146. echo "</table>";
  147. }
  148. else{
  149. echo "0 results";
  150. }
  151. ?>
  152.  
  153. <form method="post" action="index.html">
  154. <input type="submit" name="goBack" value="Back"/>
  155. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement