Guest User

Untitled

a guest
Mar 16th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. <form method="POST" action="page_next.php">
  2. <input name="first" value="">
  3. <input type="submit" value="Next">
  4. </form>
  5.  
  6. <form method="POST" action="page_last.php">
  7. <input name="second" value="">
  8. <input type="submit" value="Next">
  9. <input type="hidden" name="<?php echo $_POST['first']; ?>"
  10. </form>
  11.  
  12. <form method="POST" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
  13. <input name="last" value="">
  14. <input type="submit" value="Next">
  15. <input type="hidden" value="<?php echo $_POST['first']; ?>" name="first">
  16. <input type="hidden" value="<?php echo $_POST['second']; ?>" name="second">
  17. <input type="hidden" value="TRUE" name="submitted">
  18. </form>
  19.  
  20. <?php
  21. if ($_POST['submitted'] == true) {
  22. // your code for insert to database
  23. // example:
  24. $servername = "localhost";
  25. $username = "username";
  26. $password = "password";
  27. $dbname = "myDB";
  28.  
  29. $first = $_POST['first'];
  30. $second = $_POST['second'];
  31. $last = $_POST['last'];
  32.  
  33. // Create connection
  34. $conn = new mysqli($servername, $username, $password, $dbname);
  35. // Check connection
  36. if ($conn->connect_error) {
  37. die("Connection failed: " . $conn->connect_error);
  38. }
  39.  
  40. $sql = "INSERT INTO MyTable (first, second, last)
  41. VALUES ('$first', '$second', '$last')";
  42.  
  43. if ($conn->query($sql) === true) {
  44. echo "New record created successfully";
  45. } else {
  46. echo "Error: " . $sql . "<br>" . $conn->error;
  47. }
  48. $conn->close();
  49. }
  50. ?>
Add Comment
Please, Sign In to add comment