Guest User

Untitled

a guest
Aug 14th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. PHP/html email form no longer submitting to mysql database
  2. <form method="post" action="process-form.php" id="emailForm" name="emailForm" target="_self">
  3. <h4>Sign up to be notified when we go live!</h4>
  4. <label for="email">E-mail</label>
  5. <input type="text" name="email" id="email" />
  6. <input type="submit" name="submit" id="submit" value="Submit" onclick="return alert('Thanks! Your email has been added.');">
  7.  
  8. <p>emails will not be shared with third parties</p>
  9. </form>
  10.  
  11. <?php
  12.  
  13. //open database connect
  14. $username = "username";
  15. $password = "password";
  16. $hostname = "server";
  17.  
  18. $conn = mysql_connect($hostname, $username, $password);
  19. if (!$conn) die('Could not connect: ' . mysql_error());
  20.  
  21. //emaillist is the name of the database
  22. mysql_select_db('emaillist');
  23.  
  24. //Clean data
  25. function clean_data($string){
  26. if (get_magic_quotes_gpc()){
  27. $string = stripslashes($string);
  28. }
  29. $string = strip_tags($string);
  30. return mysql_real_escape_string($string);
  31. }
  32.  
  33. //Mail Header removal
  34. function remove_headers($string){
  35. $headers = array(
  36. "/to:/i",
  37. "/from:/i",
  38. "/bcc:/i",
  39. "/cc:/i",
  40. "/Content-Transfer-Encoding:/i",
  41. "/Content-Type:/i",
  42. "/Mime-Version:/i",
  43. );
  44.  
  45. $string = preg_replace($headers, '', $string);
  46. return strip_tags($string);
  47. }
  48.  
  49. //Pick up cleaned data
  50. $email = clean_data($_POST['email']);
  51.  
  52.  
  53. //Insert data
  54. //emails is the name of the table
  55. $query ="INSERT INTO emails (email)
  56. VALUES ('$email')";
  57.  
  58. mysql_query($query);
  59.  
  60. //close Connection
  61. mysql_close($conn);
  62.  
  63. //redirect to page
  64. header('Location: defaultUpCyc.html');
  65. ?>
  66.  
  67. if (!$conn) { die('Could not connect: ' . mysql_error()); }
Add Comment
Please, Sign In to add comment