Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!doctype html>
- <html lang="en">
- <body>
- <?php
- $host = "sis-teach-01.sis.pitt.edu";
- $user = "bmw77";
- $password = "4021930";
- $dbname = "bmw77";
- $connect = mysqli_connect($host, $user, $password, $dbname);
- // define variables and set to empty values
- $fnameErr = $lnameErr = $addressErr = $cityErr = $zipErr = $phoneErr = $quantityErr = $deliveryErr = "";
- $fname = $lname = $address = $city = $zip = $phone = $quantity = $delivery = "";
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if (empty($_POST["fname"])) {
- $fnameErr = "First Name is required";
- }
- else {
- $fname = ($_POST["fname"]);
- // check if name only contains letters and apostrophes
- if (!preg_match("/^[a-zA-Z\' ]/",$fname)) {
- $fnameErr = "Only letters and white space allowed";
- }
- }
- if (empty($_POST["lname"])) {
- $lnameErr = "Last Name is required";
- }
- else {
- $lname = ($_POST["lname"]);
- // check if name only contains letters and apostrophes
- if (!preg_match("/^[a-zA-Z\' ]/",$lname)) {
- $lnameErr = "Only letters and white space allowed";
- }
- }
- if (empty($_POST["address"])) { //address checking that something was given
- $addressErr = "Address is required";
- }
- else {
- $address = ($_POST["address"]);
- }
- if (empty($_POST["city"])) { //address checking that something was given
- $cityErr = "City is required";
- }
- else {
- $city = ($_POST["city"]);
- }
- if (empty($_POST["phone"])) { // phone number checking for numbers and 10 digits
- $phoneErr = "Phone Number is required";
- }
- else {
- $phone = ($_POST["phone"]);
- if (preg_match("/\D/",$phone)) {
- $phoneErr = "Invalid Phone Number";
- }
- if(strlen($phone) !=10){
- $phoneErr = "Please enter a 10 digit Phone Number"; // I know the homework said 9 digits but phone numbers are usually 10 so I made it 10
- }
- }
- if (empty($_POST["zip"])) { //zip checking for a zip and that it is valid
- $zipErr = "Zip Code is required";
- }
- else {
- $zip = ($_POST["zip"]);
- if (preg_match("/\D/",$zip)) {
- $zipErr = "Invalid Zip Code";
- }
- if (strlen($zip) != 5){
- $zipErr = "Zip Code should be 5 Characters" . $zip;
- }
- }
- if (empty($_POST["quantity"])) { // phone number checking for numbers and 10 digits
- $quantityErr = "Quantity is required";
- }
- else {
- $quantity = ($_POST["quantity"]);
- if (preg_match("/\D/",$quantity)) {
- $quantityErr = "Quantity must be a number";
- }
- }
- if (empty($_POST["delivery"])) { // type to check for a selection and keep it where it was
- $typeErr = "Delivery is required";
- }
- else {
- $delivery = ($_POST["delivery"]);
- }
- }
- $quantityInt = (int)$quantity;
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- $result = mysqli_query($connect, "INSERT INTO assignment6(firstName, lastName, address, city, zip, quantity, phoneNum, deliveryMethod)
- VALUES('$fname', '$lname', '$address', '$city', '$zip', '$quantityInt', '$phone', '$delivery');");
- if (!$result) {
- echo 'Could not run query: ' . mysqli_error();
- exit;
- }
- }
- $connect->close();
- ?>
- <h2>NCAA Regulation Football</h2>
- <p> Our NCAA Regulation Footballs fit the NCAA rule for size. </p>
- <img src="football.jpg">
- <p><span class="error"></span></p>
- <form method="post" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>">
- First Name: <input type="text" name="fname" value="<?php echo $fname;?>"> <!-- text box for first name returns invalid if bad characters given or nothing is given !-->
- <span class="error">* <?php echo $fnameErr;?></span>
- <br><br>
- Last Name: <input type="text" name="lname" value="<?php echo $lname;?>"> <!-- text box for last name returns invalid if bad characters given or nothing is given !-->
- <span class="error">* <?php echo $lnameErr;?></span>
- <br><br>
- Address: <input type="text" name="address" value="<?php echo $address;?>"> <!-- text box for address only returns invalid if nothing is given !-->
- <span class="error">* <?php echo $addressErr;?></span>
- <br><br>
- City: <input type="text" name="city" value="<?php echo $city;?>"> <!-- text box for city only returns invalid if nothing is given !-->
- <span class="error">* <?php echo $cityErr;?></span>
- <br><br>
- Zip Code: <input type="text" name="zip" value="<?php echo $zip;?>"> <!-- text box for zip code that requires numbers !-->
- <span class="error">* <?php echo $zipErr;?></span>
- <br><br>
- Phone Number: <input type="text" name="phone" value="<?php echo $phone;?>"> <!-- text box for phone number it forces a 10 digit number because thats what most phone numbers are !-->
- <span class="error">*<?php echo $phoneErr;?></span>
- <br><br>
- Quantity: <input type="text" name="quantity" value="<?php echo $quantity;?>"> <!-- textbox for quantity and checks that there is a value !-->
- <span class="error">*<?php echo $quantityErr;?></span>
- <br><br>
- Delivery Method <!-- Radio Buttons for final question !-->
- <input type="radio" name="delivery" <?php if (isset($delivery) && $delivery=="Standard") echo "checked";?> value="Standard">Standard
- <input type="radio" name="delivery" <?php if (isset($delivery) && $delivery=="Two-Day") echo "checked";?> value="Two-Day">Two-Day
- <input type="radio" name="delivery" <?php if (isset($delivery) && $delivery=="Next-Day") echo "checked";?> value="Next-Day">Next-Day
- <span class="error">* <?php echo $deliveryErr;?></span>
- <br><br>
- <input type="submit" name="submit" value="Submit">
- <br><br>
- <?php
- if ($_SERVER["REQUEST_METHOD"] == "POST") {
- if(($fnameErr == "") && ($lnameErr == "") && ($addressErr == "") && ($zipErr == "") && ($phoneErr == "") && ($quantityErr == "") && ($deliveryErr == "") && ($cityErr == "")){ //If statement telling that all information is valid
- echo "Order Submitted Successfully";
- }
- }
- ?>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement