Advertisement
Guest User

Untitled

a guest
Jul 30th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. $servername = "127.0.0.1";
  2. $username = "ahairlessewok";
  3. $password = "";
  4. $database = "henrybooks";
  5. $dbport = 3306;
  6.  
  7. //Make the connection
  8.  
  9. $db = new mysqli($servername, $username, $password, $database, $dbport);
  10.  
  11. // Check connection
  12. if ($db->connect_error) {
  13. die("Connection failed: " . $db->connect_error);
  14. }
  15. echo "Connected successfully (".$db->host_info.")<br><br>";
  16.  
  17. function displayForm(){
  18. echo <<< EOD
  19. <form action="add_author.php" method="post">
  20. <fieldset>
  21. Add Author:<br> <input type="text" name="name">
  22. <input type="submit" value="Submit"><br><br>
  23. </fieldset>
  24. </form>
  25. EOD;
  26. }
  27.  
  28.  
  29. //BACK BUTTON NOT WORKING FIX WHEN FINISHED
  30.  
  31.  
  32. //had a little help with this script
  33. //pretty much handles the back button
  34. function backButton(){
  35. echo "Go Back From Whence You Came!";
  36. window.history.back();
  37.  
  38. }
  39.  
  40. function getName($db){
  41.  
  42. $sql = 'INSERT INTO AUTHOR (AUTHOR_LAST) VALUES(' . $_POST['name'] . ')';
  43. $result = $db->query($sql);
  44.  
  45.  
  46.  
  47. if (mysqli_query($db, $sql)) {
  48. echo "Author Added";
  49. }
  50. else {
  51. echo "Error:" . $sql . "<br>" . mysqli_error($db);
  52. }
  53.  
  54. $db->close();
  55.  
  56. echo '
  57. <form method="post" action="program4.php">
  58. <input type="submit" value="back" name="back"> <!-- assign a name for the button -->
  59. </form> ';
  60. }
  61.  
  62.  
  63.  
  64.  
  65.  
  66. if ($_SERVER["REQUEST_METHOD"] == "POST") {
  67.  
  68.  
  69. //erases all the information is back button is pressed
  70. if(!empty($_POST['back'])) {
  71. $_POST['name'] = NULL;
  72. $_POST['title'] = NULL;
  73. $_POST['publisher'] = NULL;
  74. $_POST['back'] = NULL;
  75. displayForm();
  76. }
  77.  
  78. //else if for the author name
  79. else if(!empty($_POST['name']) ){
  80. getName($db);
  81. $_POST['name'] = NULL;
  82. }
  83.  
  84. else{
  85. displayForm();
  86. }
  87. }
  88. else{
  89. displayForm();
  90. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement