Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <div class="jumbotron text-center">
- <h1>Community Garden</h1>
- <p>We are a local community that
- grows organic vegetables and fruit</p>
- <img src="Front.jpg" class="img-rounded" alt="front" > <br><br>
- <form class="form-inline" action="news.php" method="post'>
- <div class="input-group">
- <input type="text" name="name" class="form-control" size="50" placeholder="Name" required>
- <input type="text" name="email" class="form-control" size="50" placeholder="Email Address" required>
- <br><br> <div class="input-group-btn">
- <button type="submit" name="submit" value="submit" class="btn btn-danger">Subscribe</button>
- </div>
- </div>
- </form>
- </div>
- <?php
- //include database connection details
- $username = "root";
- $password = "password";
- $hostname = "127.0.0.1";
- //connection to the database
- $dbhandle = mysql_connect($hostname, $username, $password)
- or die("Unable to connect to MySQL");
- echo "Connected to MySQL<br>";
- //select a database to work with
- $selected = mysql_select_db("Community Garden List",$dbhandle)
- or die("Could not select examples");
- if(isset($_POST['submit'])){
- //collect data from form and remove any tags and make safe for database entry
- $name = strip_tags(mysql_real_escape_string($_POST['name']));
- $email = strip_tags(mysql_real_escape_string($_POST['email']));
- //check name lengh
- if (strlen($name) < 3) {
- $error[] = 'Name must be more then 3 characters.';
- }
- //if name is equal to name then give an error
- if ($name == 'Name') {
- $error[] = 'Please enter your name.';
- }
- // check for valid email address
- $error = "";
- $pattern = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+.[A-Za-z]{2,4}$/';
- if (!preg_match($pattern, trim($email))) {
- $error[] = 'Please enter a valid email address';
- }
- // if validation is okay then carry on
- if (!$error ) {
- //insert into database
- $sql = mysql_query("INSERT INTO newsletter (name,email) VALUES ('$name','$email')")or die(mysql_error());
- //submission successful show a message
- echo "<p>Thank you, submission was successful.</p>";
- } // end validation
- }// end submit
- //show any errors
- if (!empty($error))
- {
- $i = 0;
- while ($i < count($error)){
- echo '<div class="msg-error">".$error[$i]."</div>';
- $i ++;}
- }// close if empty errors
- ?>
Add Comment
Please, Sign In to add comment