Created
April 26, 2020 14:57
-
-
Save 14sprouj/0ea54699549aa48b6c06227bd28b96c6 to your computer and use it in GitHub Desktop.
PHP files (collection of 3) to place an order for a cake
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
<style> | |
table, tr, td { | |
border: 1pt solid black; | |
border-collapse: collapse; | |
} | |
</style> | |
</head> | |
<body> | |
<?php | |
include 'includes/header.php'; | |
echo "Please check all details before proceding"; | |
$_SESSION["occasion"] = $_POST["occasion"]; | |
$_SESSION["pm"] = $_POST["pm"]; | |
$_SESSION["date"] = $_POST["date"]; | |
$_SESSION["flavour"] = $_POST["flavour"]; | |
$_SESSION["colour1"] = $_POST["colour1"]; | |
$_SESSION["colour2"] = $_POST["colour2"]; | |
$_SESSION["shape"] = $_POST["shape"]; | |
$_SESSION["size"] = $_POST["size"]; | |
$_SESSION["icing"] = $_POST["icing"]; | |
$_SESSION["extras"] = $_POST["extras"]; | |
$_SESSION["comment"] = $_POST["comment"]; | |
$_SESSION["vegan"] = $_POST["vegan"]; | |
$_SESSION["fname"] = $_POST["fname"]; | |
$_SESSION["lname"] = $_POST["lname"]; | |
$_SESSION["ship-address"] = $_POST["ship-address"]; | |
$_SESSION["ship-city"] = $_POST["ship-city"]; | |
$_SESSION["ship-zip"] = $_POST["ship-zip"]; | |
$_SESSION["ship-country"] = $_POST["ship-country"]; | |
$_SESSION["phone"] = $_POST["phone"]; | |
$_SESSION["email"] = $_POST["email"]; | |
?> | |
<table> | |
<tr> | |
<td>Occasion</td> | |
<td><?php echo $_POST["occasion"]; ?></td> | |
</tr> | |
<tr> | |
<td>Personalised Message on cake</td> | |
<td><?php echo $_POST["pm"]; ?></td> | |
</tr> | |
<tr> | |
<td>Date needed for</td> | |
<td><?php echo $_POST["date"]; ?></td> | |
</tr> | |
<tr> | |
<td>Flavour</td> | |
<td><?php echo $_POST["flavour"]; ?></td> | |
</tr> | |
<tr> | |
<td>Colour</td> | |
<td><?php echo $_POST["colour1"]; ?> and <?php echo $_POST["colour2"]; ?></td> | |
</tr> | |
<tr> | |
<td>Shape</td> | |
<td><?php echo $_POST["shape"]; ?></td> | |
</tr> | |
<tr> | |
<td>Size</td> | |
<td><?php echo $_POST["size"]; ?></td> | |
</tr> | |
<tr> | |
<td>Icing</td> | |
<td><?php echo $_POST["icing"]; ?></td> | |
</tr> | |
<tr> | |
<td>Extras</td> | |
<td> | |
<?php | |
if(!empty($_POST['extras'])) { | |
// Counting number of checked checkboxes. | |
$checked_count = count($_POST['extras']); | |
echo "You have selected following ".$checked_count." option(s): <br/>"; | |
echo "<ul>"; | |
foreach($_POST['extras'] as $selected) { | |
echo "<li style='margin-left:20pt;'>".$selected ."</li>"; | |
$extraslist = $extraslist." ".$selected; | |
} | |
echo "</ul>"; | |
$_SESSION["extraslist"] = $extraslist; | |
} | |
else{ | |
echo "No extras selected."; | |
} | |
?> | |
</td> | |
</tr> | |
<tr> | |
<td>Comment</td> | |
<td><?php echo $_POST["comment"]; ?> <?php echo $_POST["vegan"]; ?></td> | |
</tr> | |
<tr> | |
<td colspan="2"><b style="text-align:center;">Your Details</b></td> | |
</tr> | |
<tr> | |
<td>Name</td> | |
<td><?php echo $_POST["fname"]; ?> <?php echo $_POST["lname"]; ?></td> | |
</tr> | |
<tr> | |
<td>Address</td> | |
<td><?php echo $_POST["ship-address"]; ?><br><?php echo $_POST["ship-city"]; ?><br><?php echo $_POST["ship-zip"]; ?><br><?php echo $_POST["ship-country"]; ?></td> | |
</tr> | |
<tr> | |
<td>Phone Number</td> | |
<td><?php echo $_POST["phone"]; ?></td> | |
</tr> | |
<tr> | |
<td>Email</td> | |
<td><?php echo $_POST["email"]; ?></td> | |
</tr> | |
</table> | |
<a href="place.php">Place order</a> | |
<script> | |
</script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h2>Order a cake</h2> | |
<p style="text-align:center;">Use this form to order a cake</p> | |
<form class="" action="confirm.php" method="post" style=""> | |
<div style="column-count:2;"> | |
<label for="occasion">What occasion is the cake for? <i class="required"></i></label> | |
<select class="" name="occasion" required> | |
<option value="" disabled selected></option> | |
<option value="Birthday">Birthday</option> | |
<option value="Wedding">Wedding</option> | |
<option value="Christening">Christening</option> | |
<option value="Valentines Day">Valentine's Day</option> | |
<option value="Easter">Easter</option> | |
<option value="Christmas">Christmas</option> | |
<option value="Mothers Day">Mother's Day</option> | |
<option value="Fathers Day">Father's Day</option> | |
</select> | |
<br> | |
<label for="pm" style="vertical-align: top;">Personalised message on cake <i class="required" style="vertical-align: top;"></i></label> | |
<textarea name="pm" cols="40" required style="height:120px;"></textarea> | |
<br> | |
<label for="date">Date it's needed for <i class="required"></i></label> | |
<input id="datefield" type='date' name="date" min='<?php | |
$date = date('Y-m-d'); | |
echo date('Y-m-d', strtotime($Date. ' + 5 days')); | |
?>' max='2000-13-13' required></input> | |
<br> | |
<label for="flavour">Flavour <i class="required"></i></label> | |
<select class="" name="flavour" required> | |
<option value="" disabled selected></option> | |
<option value="Carrot">Carrot</option> | |
<option value="Chocolate">Chocolate</option> | |
<option value="Coconut">Coconut</option> | |
<option value="Coffee and Walnut">Coffee and Walnut</option> | |
<option value="Lemon">Lemon</option> | |
<option value="Rum and Fruit">Rum & Fruit</option> | |
<option value="Strewberry and Vanilla Cream">Strewberry and Vanilla Cream</option> | |
<option value="Vanilla">Vanilla</option> | |
<option value="Other">Other (Please contact supplier)</option> | |
</select> | |
<br> | |
<label for="colour">Theme Colours <i class="required"></i></label> | |
<input type="color" name="colour1" required> | |
<input type="color" name="colour2" required> | |
<br> | |
<label for="shape">Shape <i class="required"></i></label> | |
<select class="" name="shape" required> | |
<option value="" disabled selected></option> | |
<option value="Circle">Circle</option> | |
<option value="Square">Square</option> | |
</select> | |
<br> | |
<label for="size">Size <i class="required"></i></label> | |
<select name="size" required> | |
<option value="" disabled selected></option> | |
<option value="8">8"</option> | |
<option value="10">10"</option> | |
<option value="12">12"</option> | |
<option value="14">14"</option> | |
</select> | |
<label for="layers">Number of Layers <i class="required"></i></label> | |
<select name="layers" required> | |
<option value="" disabled selected></option> | |
<option value="1">1</option> | |
<option value="2">2</option> | |
<option value="3">3</option> | |
<option value="4">4</option> | |
</select> | |
<br> | |
<label for="icing">Icing <i class="required"></i></label> | |
<select class="" name="icing" required> | |
<option value="" disabled selected></option> | |
<option value="Chocolate">Chocolate</option> | |
<option value="Buttercream">Buttercream</option> | |
<option value="Italian Cream">Italian Cream</option> | |
<option value="White Chocolate">White Chocolate</option> | |
<option value="Fondant">Fondant</option> | |
</select> | |
<br> | |
<label for="extras"><b>Select Extras</b></label><br> | |
<input type="checkbox" name="extras[]" value="Sprinkles"> Sprinkles | |
<input type="checkbox" name="extras[]" value="Cake Toppers"> Cake Toppers | |
<br> | |
<label for="comment">Anything else we need to know?</label> | |
<br> | |
<textarea name="comment" rows="5" cols="50"></textarea> | |
<br> | |
<input type="checkbox" name="vegan" value="Yes"> Vegan? | |
<hr> | |
<label for="name">Name <i class="required"></i></label> | |
<input name="fname" id="fname" placeholder="First Name" required autocomplete="given-name"> | |
<input name="lname" id="lname" placeholder="Last Name" required autocomplete="family-name"> | |
<br> | |
<label for="address">Address <i class="required"></i></label> | |
<input name="ship-address" required id="address" placeholder="123 Any Street" autocomplete="shipping street-address"> | |
<wbr> | |
<label for="city">City <i class="required"></i></label> | |
<input name="ship-city" required id="city" placeholder="London" autocomplete="shipping locality"> | |
<wbr> | |
<label for="postcode">Postcode <i class="required"></i></label> | |
<input name="ship-zip" required id="frmZipS" placeholder="P0ST C0D3" autocomplete="shipping postal-code"> | |
<wbr> | |
<label for="country">Country <i class="required"></i></label> | |
<input name="ship-country" required id="country" placeholder="GB" autocomplete="shipping country"> | |
<br> | |
<label for="number">Phone Number <i class="required"></i></label> | |
<input type="tel" name="phone" required autocomplete="tel"> | |
<br> | |
<label for="email">Email <i class="required"></i></label> | |
<input type="email" name="email" required autocomplete="email"> | |
</div> | |
<input type="submit" name="" style="text-align:center;" value="Place Order"> | |
</form> | |
<br> | |
</div> | |
<script> | |
var today = new Date(); | |
var dd = today.getDate(); | |
var mm = today.getMonth()+1; //January is 0! | |
var yyyy = today.getFullYear(); | |
if(dd<10){ | |
dd='0'+dd | |
} | |
if(mm<10){ | |
mm='0'+mm | |
} | |
var yyyy1 = yyyy+1; | |
today = yyyy+'-'+mm+'-'+dd; | |
todayAdd1y = yyyy1+'-'+mm+'-'+dd; | |
document.getElementById("datefield").setAttribute("max", todayAdd1y); | |
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
session_start(); | |
?> | |
<!DOCTYPE html> | |
<html> | |
<head> | |
<title></title> | |
</head> | |
<body> | |
<?php | |
$servername = "server"; | |
$username = "username"; | |
$password = "password"; | |
$dbname = "database-name"; | |
// Convert Long Strings | |
$comments = htmlentities($_SESSION['comments']); | |
// Create connection | |
$conn = new mysqli($servername, $username, $password, $dbname); | |
// Check connection | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error); | |
} | |
$sql = "INSERT INTO `test` (`First Name`, `Last Name`, `Address`, `City`, `Country`, `email`, `phone number`, `occassion`, `message on cake`, `date needed`, `flavour`, `colour1`, `colour2`, `shape`, `size`, `layers`, `icing`, `extras`, `vegan`, `comments`) VALUES ('{$_SESSION["fname"]}', '{$_SESSION["lname"]}', '{$_SESSION["ship-address"]}', '{$_SESSION["ship-city"]}', '{$_SESSION["ship-country"]}', '{$_SESSION["email"]}', '{$_SESSION["phone"]}', '{$_SESSION["occasion"]}', '{$_SESSION["pm"]}', '{$_SESSION["date"]}', '{$_SESSION["flavour"]}', '{$_SESSION["colour1"]}', '{$_SESSION["colour2"]}', '{$_SESSION["shape"]}', '{$_SESSION["size"]}', '{$_SESSION["layers"]}', '{$_SESSION["icing"]}', '{$_SESSION["extraslist"]}', '{$_SESSION["vegan"]}', '$comments')"; | |
if ($conn->query($sql) === TRUE) { | |
echo "New record created successfully"; | |
// remove all session variables | |
session_unset(); | |
// destroy the session | |
session_destroy(); | |
header("Location: done.php"); | |
} | |
else { | |
echo "We seem to have an issue. Please try calling instead and let us know you've had an issue. Sorry for any inconvenice."; | |
echo "Error: " . $sql . "<br>" . $conn->error; | |
} | |
$conn->close(); | |
?> | |
<script> | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment