Advertisement
Guest User

Untitled

a guest
Jun 25th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.43 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>How To Insert Data Into MySQL db using form in php</title>
  4. </head>
  5. <body>
  6. <?php
  7. $hostname = "10.15.14.247"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost
  8. $db_user = "root"; // change to your database password
  9. $db_password = "master"; // change to your database password
  10. $database = "acesbd"; // provide your database name
  11. $db_table = "tipo_actividade"; // leave this as is
  12.  
  13.  
  14. $db = mysql_connect($hostname, $db_user, $db_password);
  15. mysql_select_db($database,$db);
  16.  
  17. ?>
  18.  
  19.  
  20. <?php
  21. if (isset($_REQUEST['Submit'])) {
  22.  
  23. $sql = "INSERT INTO $db_table(TAC_nome) values ('".mysql_real_escape_string(stripslashes($_REQUEST['TAC_nome']))."')";
  24. if($result = mysql_query($sql ,$db)) {
  25. echo "<h1>Thank you</h1><br>Your information has been entered into our database<br><br>";
  26.  
  27. } else {
  28. echo "ERROR: ".mysql_error();
  29. }
  30. }
  31.  
  32.  
  33. echo "<form method='post' action=''>";
  34.  
  35. $sqlin = "SELECT count(*) FROM tipo_actividade";
  36. $result = mysql_query($sqlin ,$db);
  37.  
  38. echo"<h1>Gestão de tipo de actividades</h1>";
  39.  
  40.  
  41. $row = mysql_fetch_array($result);
  42. $ID = $row[0] + 1;
  43. $total = $row[0];
  44.  
  45. $index = 1;
  46.  
  47. echo"<br>TAC_ID:<br>";
  48. echo"<input type='text' name='TAC_ID' value=$ID readonly='readonly'>";
  49. echo"<br>";
  50. echo"TAC_nome: <br>";
  51. echo"<input type='text'' name='TAC_nome' >";
  52. echo"<br>";
  53. echo"<input type='submit' name='Submit' value='Submit'>";
  54. echo"</form>";
  55.  
  56.  
  57. if (!isset($SearchTAC_ID)) {
  58. $SearchTAC_ID = 1;
  59. $index = 1;
  60. }
  61.  
  62.  
  63. if ($SearchTAC_ID == 1) {
  64. $sqlsearch = "SELECT * FROM $db_table where TAC_ID = $SearchTAC_ID";
  65. if($result = mysql_query($sqlsearch ,$db)) {
  66. $row = mysql_fetch_array($result);
  67. $SearchTAC_nome = $row[1];
  68.  
  69. } else {
  70. echo "ERROR: ".mysql_error();
  71. }
  72. }
  73.  
  74.  
  75.  
  76. if (isset($_REQUEST['proximo']) and ($index < $total) ) {
  77. $sqlsearch = "SELECT * FROM $db_table WHERE TAC_ID > $SearchTAC_ID ORDER BY TAC_ID ASC LIMIT 1";
  78. if($result = mysql_query($sqlsearch ,$db)) {
  79. $row = mysql_fetch_array($result);
  80. $index++;
  81. echo"<br>index2: $index <br>";
  82.  
  83. $SearchTAC_ID = $row[0];
  84. $SearchTAC_nome = $row[1];
  85. } else {
  86. echo "ERROR1: ".mysql_error();
  87. }
  88. }
  89.  
  90. echo"<br>TAC_total: $total <br>";
  91.  
  92. if (isset($_REQUEST['anterior']) and ($index > 1) ) {
  93. $sqlsearch = "SELECT * FROM $db_table WHERE TAC_ID < $SearchTAC_ID ORDER BY TAC_ID DESC LIMIT 1";
  94.  
  95. if($result = mysql_query($sqlsearch ,$db)) {
  96. $row = mysql_fetch_array($result);
  97. $index--;
  98. $SearchTAC_ID = $row[0];
  99. $SearchTAC_nome = $row[1];
  100. } else {
  101. echo "ERROR2: ".mysql_error();
  102. }
  103. }
  104.  
  105.  
  106. if (isset($_REQUEST['apagar']) ) {
  107. $sqlsearch = "DELETE FROM $database.$db_table WHERE $db_table.`TAC_ID` = $SearchTAC_ID";
  108.  
  109. if($result = mysql_query($sqlsearch ,$db)) {
  110. //$row = mysql_fetch_array($result);
  111. echo " $row <br>";
  112. } else {
  113. echo "ERROR2: ".mysql_error();
  114. }
  115. }
  116.  
  117.  
  118. echo"<form action='' method='post'>";
  119. echo"Search: ";
  120. echo"<br>TAC_ID:<br>";
  121. echo"<input type='text' name='SearchTAC_ID' value=$SearchTAC_ID readonly='readonly'>";
  122. echo"<br>";
  123. echo"TAC_nome: <br>";
  124. echo"<input type='text' name='SearchTAC_nome' value=$SearchTAC_nome>";
  125. echo"<br>";
  126. echo"<br>";
  127. echo"<input type='submit' name='anterior' value='anterior' > <input type='submit' name='proximo' value='proximo' >";
  128. echo"<input type='submit' name='apagar' value='apagar' > <input type='submit' name='actualizar' value='actualizar' >";
  129. echo"</form>";
  130. ?>
  131.  
  132.  
  133.  
  134.  
  135. </body>
  136. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement