Guest User

Untitled

a guest
Jan 3rd, 2018
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. <div class="jumbotron text-center">
  2. <h1>Community Garden</h1>
  3. <p>We are a local community that
  4. grows organic vegetables and fruit</p>
  5. <img src="Front.jpg" class="img-rounded" alt="front" > <br><br>
  6. <form class="form-inline" action="news.php" method="post'>
  7. <div class="input-group">
  8. <input type="text" name="name" class="form-control" size="50" placeholder="Name" required>
  9. <input type="text" name="email" class="form-control" size="50" placeholder="Email Address" required>
  10. <br><br> <div class="input-group-btn">
  11. <button type="submit" name="submit" value="submit" class="btn btn-danger">Subscribe</button>
  12. </div>
  13. </div>
  14. </form>
  15. </div>
  16.  
  17. <?php
  18. //include database connection details
  19. $username = "root";
  20. $password = "password";
  21. $hostname = "127.0.0.1";
  22.  
  23. //connection to the database
  24. $dbhandle = mysql_connect($hostname, $username, $password)
  25. or die("Unable to connect to MySQL");
  26. echo "Connected to MySQL<br>";
  27.  
  28. //select a database to work with
  29. $selected = mysql_select_db("Community Garden List",$dbhandle)
  30. or die("Could not select examples");
  31.  
  32. if(isset($_POST['submit'])){
  33.  
  34. //collect data from form and remove any tags and make safe for database entry
  35. $name = strip_tags(mysql_real_escape_string($_POST['name']));
  36. $email = strip_tags(mysql_real_escape_string($_POST['email']));
  37.  
  38. //check name lengh
  39. if (strlen($name) < 3) {
  40. $error[] = 'Name must be more then 3 characters.';
  41. }
  42.  
  43. //if name is equal to name then give an error
  44. if ($name == 'Name') {
  45. $error[] = 'Please enter your name.';
  46. }
  47.  
  48. // check for valid email address
  49. $error = "";
  50. $pattern = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
  51. if (!preg_match($pattern, trim($email))) {
  52. $error[] = 'Please enter a valid email address';
  53. }
  54.  
  55. // if validation is okay then carry on
  56. if (!$error ) {
  57.  
  58. //insert into database
  59. $sql = mysql_query("INSERT INTO newsletter (name,email) VALUES ('$name','$email')")or die(mysql_error());
  60.  
  61. //submission successful show a message
  62. echo "<p>Thank you, submission was successful.</p>";
  63.  
  64. } // end validation
  65. }// end submit
  66.  
  67. //show any errors
  68. if (!empty($error))
  69. {
  70. $i = 0;
  71. while ($i < count($error)){
  72. echo '<div class="msg-error">".$error[$i]."</div>';
  73. $i ++;}
  74. }// close if empty errors
  75.  
  76. ?>
Add Comment
Please, Sign In to add comment