Guest User

Untitled

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