Creating a form.

One of the forms we had to create was a comment form, this form was used to allow users to comment there own days out and give a location price and a rating out of ten, this feature also made our website a UGC application as it allows users to add there own days out. The form included:

·         Location

·         Rating 1-5

·         Name

·         Description

The form includes a series of boxes that need to be filled out and if their not filled out an error message will appear saying “something went wrong” this shows how our web application is responsive and works by sending data to a database and responds with messages.

Below is the form for uploading your day out:

<?php require_once("../includes/session.php"); ?>
<?php require_once("../includes/connect.php"); ?>
<?php require_once("../includes/functions.php"); ?>
 if(isset($_POST["submit"])) {
$name = $_POST["name"];
 $description = $_POST["description"];
 $location = $_POST["location"];
 $rating = $_POST["Rating"];
if(empty($name)) {
 $message = "Invalid name";
 } else if(empty($description)) {
 $message = "Invalid Description";
 } else if(empty($location)) {
 $message = "Invalid location";
 } else if(empty($rating)) {
 $message = "Please rate your activity";
 } else {
 $query = "INSERT INTO form (name, description, location, rating) VALUES ('{$name}', '{$description}', '{$location}', '{$rating}')";
$result = mysqli_query($connection, $query);
if($result) {
 $message = "Your day was added";
 } else {
 $message = "something went wrong";
$name = "";
 $description = "";
 $location = "";
 $rating = "";
$query = "SELECT name, description, location, rating FROM form";
$result = mysqli_query($connection, $query);
$rowcount = mysqli_num_rows($result);
<!doctype html>
 <title>Format Code</title>
 <link href="css/styles.css" rel="stylesheet" >
<?php include 'nav.php'; ?>
<div class="top-title">
 <h1>Submit your day out!</h1>
<div class="container">
 if(isset($message)) {
 echo $message;
<form action="submit-day.php" method="post">
 Please Name activity: <input type="text" name="name" value="" />
 Describe your activity: <input type="text" name="description" value="" />
 Location: <input type="text" name="location" value="" />
 Please rate activity: <select name="rating">
 <option value="1">1</option>
 <option value="2">2</option>
 <option value="3">3</option>
 <option value="4">4</option>
 <option value="5">5</option>
 <input type="submit" name="submit" value="Submit" />
 if ($rowcount > 0) {
 while($row = mysqli_fetch_assoc($result)) {
<div class="day-box">
 <h1><?php echo $row["name"]; ?></h1>
 <p><?php echo $row["description"]; ?></p>
 <p><?php echo $row["location"]; ?></p>
 <p><?php echo $row["rating"]; ?></p>
 <?php if($row["rating"] == 5) { ?>
 <img src="images/stars.jpg">
 <?php } ?>
 <?php }
} else {
 echo "0 results";
Here is our working form:Screen Shot 2015-04-20 at 10.13.14

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s