Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.85 KB | None | 0 0
  1. <form id="form" name="contactForm" method="post" action="php/form.php">
  2. <div>
  3. <label for="name">Your name</label>
  4. <input type="text" id="name" name="name" maxlength="40" placeholder="Write your Name" >
  5. <span class="error"><?php echo $nameError; ?></span>
  6. </div>
  7. <div>
  8. <label for="email">Your email</label>
  9. <input type="email" id="email" name="user_mail" placeholder="email@example.com">
  10. <span class="error"><?php echo $emailError; ?></span>
  11. </div>
  12. <div>
  13. <label for="topic">Select Topic</label>
  14. <select id="topic" name="topic">
  15. <option selected disabled hidden value="">Choose a Topic</option>
  16. <option value="link">Site Link</option>
  17. <option value="copyright">Copyright</option>
  18. <option value="errors">Site/Article errors</option>
  19. <option value="feedback">Feedback</option>
  20. <option value="other">Other</option>
  21. </select>
  22. <span class="error"><?php echo $topicError; ?></span>
  23. </div>
  24. <div>
  25. <label for="msg">Your message</label>
  26. <textarea id="msg" name="user_message" placeholder="Write your message"></textarea>
  27. <span class="error"><?php echo $msgError; ?></span>
  28. </div>
  29. <div class="button">
  30. <button type="submit" id="submit" name="submit" value="true">Submit</button>
  31. <span class="success"></span>
  32. </div>
  33. </form>
  34.  
  35. <?php
  36.  
  37.  
  38. $servername = "localhost:3306";
  39. $username = "root";
  40. $password = "";
  41. $dbname = "site_comboios";
  42.  
  43. $name = $_POST['name'];
  44. $email = $_POST['user_mail'];
  45. $topic = $_POST['topic'];
  46. $msg = $_POST['user_message'];
  47.  
  48. $nameError = "";
  49. $emailError = "";
  50. $topicError = "";
  51. $msgError = "";
  52.  
  53. if( !empty( $_POST['submit'])) {
  54. if(empty( $name) || !isset($name) ) {
  55. $nameError = "Name is required" ;
  56. }
  57.  
  58. if(empty( $email) || !isset($email)) {
  59. $emailError = "Email is required";
  60. } elseif(filter_var($email,FILTER_VALIDATE_EMAIL)) {
  61. $emailError = "Please insert a correct email address";
  62. }
  63.  
  64. if(empty( $topic) || !isset($topic) ) {
  65. $topicError = "Please choose a topic";
  66. }
  67.  
  68. if(empty( $msg) || !isset($msg) ) {
  69. $msgError = "Let us know your opinion";
  70. }
  71. }
  72.  
  73. //Create connection to database
  74. $mysqli = new mysqli($servername, $username, $password, $dbname);
  75.  
  76. //check connection
  77. if($mysqli->connect_errno) {
  78. echo 'Error connecting to database';
  79. }
  80.  
  81. //Prepared Statement
  82. $stmt = $mysqli->prepare("INSERT INTO contacts(Nome, Email, Topico, Mensagem) VALUES(?, ?, ?, ?)" );
  83. $stmt->bind_param('ssss', $name, $email, $topic, $msg);
  84. $stmt->execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement