Guest User

Untitled

a guest
Nov 27th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. <?php
  2. if(session_status() == PHP_SESSION_NONE) {
  3. session_start();
  4.  
  5. }
  6.  
  7. /*Connect with the DB*/
  8. $servername = "localhost";
  9. $username = "root";
  10. $password = "";
  11. $dbname = "project";
  12.  
  13. $conn = new mysqli($servername, $username, $password, $dbname);
  14. ?>
  15.  
  16. <?php
  17. include('Conexion.php');
  18. ?>
  19.  
  20. <form method="post" action="registerExercise.php">
  21.  
  22. <div class="input-group">
  23. <label>Title</label>
  24. <input type="title" name="title" value="">
  25. </div>
  26. <div class="input-group">
  27. <label>Text</label>
  28. <input type="text" name="text" value="">
  29. </div>
  30.  
  31.  
  32.  
  33. <div class="input-group">
  34. <button type="submit" class="btn" name="reg_exercise">Add exercise</button>
  35. </div>
  36.  
  37. </form>
  38.  
  39. <?php
  40.  
  41. include('Conexion.php');
  42.  
  43. // REGISTER USER
  44. if (isset($_POST['reg_exercise'])) {
  45. // receive all input values from the form
  46. $title = mysqli_real_escape_string($conn, $_POST['title']);
  47. $text = mysqli_real_escape_string($conn, $_POST['text']);
  48.  
  49.  
  50. if (empty($title)) { array_push($errors, "Title is required"); }
  51. if (empty($text)) { array_push($errors, "Text is required"); }
  52.  
  53.  
  54. $query = "INSERT INTO exercises (title, text, null, null, null, null, null, null, null)
  55. VALUES('$title', '$text', null, null, null, null, null, null, null)";
  56.  
  57. mysqli_query($conn, $query);
  58. header('location: index.php');
  59. }
  60. ?>
Add Comment
Please, Sign In to add comment