Advertisement
Guest User

Untitled

a guest
Apr 20th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.13 KB | None | 0 0
  1. <?php
  2. session_start();
  3. if(isset ($_SESSION['uname']) == "true") //If this is a valid user allow access to this page
  4. {
  5. if(isset($_POST["submit"]))
  6. {
  7. //The form has been submitted and needs to be processed
  8.  
  9. include 'connectionAgain.php'; //connects to the database
  10.  
  11. //Validate the form data here!
  12.  
  13. //Get the name value pairs from the $_POST variable into PHP variables
  14. //uses the same name/value pairs from the form
  15. /*$event_id = $_POST[event_id];
  16. $event_name = $_POST[event_name];
  17. $event_description = $_POST[event_description];
  18. $event_presenter = $_POST[event_presenter];
  19. $event_date = $_POST[event_date];
  20. $event_time = $_POST[event_time];*/
  21.  
  22. $sqlHardCode = "INSERT INTO nephilim42_341 . wdv341 (event_id, event_name, event_description, event_presenter, event_date, event_time) VALUES (?, ?, ?, ?, ?, ?);";
  23. //Create the SQL command string
  24. /*$sql = "INSERT INTO wdv341 (";
  25. $sql .= "event_id, ";
  26. $sql .= "event_name, ";
  27. $sql .= "event_description, ";
  28. $sql .= "event_presenter, ";
  29. $sql .= "event_date, ";
  30. $sql .= "event_time"; //Last column does NOT have a comma after it.
  31. $sql .= ") VALUES (?,?,?,?,?,?)";*/ //? Are placeholders for variables
  32.  
  33. //Display the SQL command to see if it correctly formatted.
  34. echo "<p>$sql</p>";
  35.  
  36. $query = $connection->prepare($sql); //Prepares the query statement
  37.  
  38. //Binds the parameters to the query.
  39. //s = string: i = integer: b = blob: d = double: (DATATYPES)
  40. $query->bind_param("ssssss",null, $event_name, $event_description, $event_presenter, $event_date, $event_time);
  41.  
  42. //Run the SQL prepared statements
  43. if ( $query->execute() )
  44. {
  45. $sqlHardCode = "INSERT INTO nephilim42_341 . wdv341 (null, event_name, event_description, event_presenter, event_date, event_time) VALUES ( $event_name, $event_description, $event_presenter, $event_date, $event_time);";
  46. /*$sql = "INSERT INTO wdv341 (";
  47. $sql .= "event_id, ";
  48. $sql .= "event_name, ";
  49. $sql .= "event_description, ";
  50. $sql .= "event_presenter, ";
  51. $sql .= "event_date, ";
  52. $sql .= "event_time"; //Last column does NOT have a comma after it.
  53. $sql .= ") VALUES ($event_id,$event_name,$event_description,$event_presenter,$event_date,$event_time)";*/
  54.  
  55. $message = "<h1>Your record has been successfully added to the database.</h1>";
  56. $message .= "<p>Please <a href='redirect.php'>view</a> your records.</p>";
  57. }
  58. else
  59. {
  60. $message = "<h1>You have encountered a problem.</h1>";
  61. $message .= "<h2 style='color:red'>" . mysqli_error($link) . "</h2>"; //remove this for production purposes
  62. }
  63.  
  64. $query->close();
  65. $connection->close(); //closes the connection to the database once this page is complete.
  66. }// ends if submit
  67. else
  68. {
  69. header('location: redirect.php');
  70. //Form has not been seen by the user. display the form
  71. }
  72. }//end Valid User True
  73. else
  74. {
  75. //Invalid User attempting to access this page. Send person to Login Page
  76. //header('Location: loginPage.php');
  77. }
  78. ?>
  79. <!DOCTYPE html>
  80. <html>
  81. <head>
  82. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  83. <title>WDV341 Into PHP - Event Form</title>
  84. <style>
  85. html {
  86. color: white;
  87. }
  88.  
  89. body {
  90. background-color: black;
  91. }
  92. </style>
  93.  
  94. </head>
  95.  
  96. <body>
  97. <?php
  98. if(isset($_POST["submit"]))
  99. {
  100. //If the form was submitted display the INSERT result message
  101. ?>
  102. <h1><?php echo $message = 'Your record has been successfully entered into the database'; ?></h1>
  103. <h1><?php echo "Return to <a href='eventInsertForm.php'>Event Form</a>to enter more events";?></h1>
  104.  
  105. <?php
  106. }//end if
  107. else
  108. {
  109. //Display the Form. The user will add a new record
  110. include 'redirect.php';
  111. ?>
  112.  
  113. <p>This is the input form that allows the user/customer to enter the information for an event. Once the form is submitted and validated it will call the addPresenters.php page. That page will pull the form data into the PHP and add a new record to the database.</p>
  114. <form id="eventForm" name="eventForm" method="post" action="eventInsertForm.php">
  115. <p>Add a new Event</p>
  116. <p>Event Name:
  117. <input type="text" name="event_name" id="event_name" />
  118. </p>
  119. <p>Event Description:
  120. <textarea name="event_description" id="event_description" col = "45" rows = "5"></textarea>
  121. </p>
  122. <p>Event Presenter:
  123. <input type="text" name="event_presenter" id="event_presenter" />
  124. </p>
  125. <p>Event Date:
  126. <input type="text" name="event_date" id="event_date" />
  127. </p>
  128. <p>Event Time:
  129. <input type="text" name="event_time" id="event_time" />
  130. </p>
  131. <p>
  132. <input type="submit" name="submit" id="submit" value="Add Event" />
  133. <input type="reset" name="button2" id="button2" value="Clear Form" />
  134. </p>
  135. </form>
  136. <?php
  137. }//end else
  138. ?>
  139. </body>
  140. </html>
  141.  
  142. <?php
  143. // This file contains the PHP coding to connect to the database. This file uses the mysqli or improved mysql commands.
  144. //
  145. // Include this file in any page that needs to access the database. Use the PHP include command before doing any database accesses
  146. //
  147.  
  148. $hostname = "localhost";
  149. $username = "";
  150. $database = "";//the name of the database. Usually the same as the username.
  151. $password = "";
  152.  
  153. //Builds the connection object called $db and selects the desired database.
  154. //You will need to use the $link variable in the mysqli_query() commands whenever you run a query against the database.
  155. $link = mysqli_connect($hostname, $username, $password, $database); //$link is the connection object created by this command.
  156.  
  157. //$link is a doorway to hell!!!
  158.  
  159. //Check to make sure you properly connected to the database. This is some sample logic more suitable to a production environment
  160. if($link->connect_error)
  161. {
  162. die("Connection Failed: " . $link->connect_error);
  163. }
  164. else
  165. {
  166. echo "Connected Successfully";
  167. }
  168.  
  169. //Alternative method of checking for a successful connection.
  170.  
  171. $link = mysqli_connect($hostname,$username,$password,$database) or die("Error " . mysqli_error($link));
  172. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement