无法获取将信息提交到PHP页面的表单

时间:2019-04-16 04:09:30

标签: php html sql

我正在处理一个Web表单,该表单允许人们将用户信息输入到预订页面,该页面将使用PHP提交到另一个页面。截至目前,当我单击我的提交按钮时,它直接将我带到我的PHP页面,但只显示PHP代码,而不显示他们提交的信息。我希望能够单击“提交”按钮并在我的contactform.php页面上显示信息。

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>Reservations</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
   <link rel="stylesheet" type="text/css" href="travel.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
   <link rel="icon" href="travel.png">
</head>
 <header>
      <img class="imageheader" src="travel.PNG" alt="megatravel" align="left" width="145" height="145">
<div class="wrapper">
    <nav role="navigation">
      <h1><a href="travelindex.html">Mega Travel</a></h1>
      <ul class="nav-ul">
        <li><a href="travelindex.html">Home</a></li>
        <li><a href="aboutus.html">About Us</a></li>
        <li><a href="reservations.html">Reservations</a></li>
      </ul>
    <a href="aboutus.html"><a/>
    <a href="travelindex.html"><a/>
    </nav>
  </header>

<img class="image1" src="brisbane.png" align="middle" height="330" width="870" border="inset"/>
<img class="image2" src="vancouver.png" align="middle" height="340" width="870" border="inset"/>
<img class="image3" src="newyorkcity.png" align="middle" height="340" width="870" border="inset"/>
<img class="image4" src="berlin.png" align="middle" height="340" width="870" border="inset"/>

<div class="col-sm-4" style="background-color:white";>

      <h1 class="form-group">Reservations</h1>
      <form action="contactform.php" method="post" id="travelform">
        <fieldset>
          <legend>Contact Information</legend>
          <label for="firstname">First Name:</label>
          <input type="text" id="firstName" name="firstname" class="form-control"><br>
          <label for="middlename">Middle Name:</label>
          <input type="text" id="middleName" name="middlename" class="form-control"><br>
          <label for="lastname">Last Name:</label>
          <input type="text" id="lastName" name="lastname" class="form-control"><br>
          <label for="phone"> Phone Number: </label>
          <input type="tel" id="phoneNum" name="phone" class="form-control"><br>
          <label for="email">Email Address: </label>
          <input type="email" id="Email" name="email" class="form-control"><br>
        </fieldset>
<fieldset>
  <legend>Travel Information</legend>
     <label for="locations">Current Locations:</label>
       <select name="locations" id="Locations" onchange="changeActivities()" class="form-control">
        <option value="australia">Brisbane</option>
        <option value="canada">Vancouver</option>
        <option value="newyork">New York City</option>
        <option value="germany">Berlin</option>
        <option value="mexico">Cancun</option>
         </select><br>
          <label for="depart_Date">Departure Date: </label>
          <input type="date" name="depart_Date" id="depart_Date" class="form-control">
          <label for="return_Date">Return Date: </label><br>
          <input type="date" name="return_Date" id="return_Date" class="form-control">
          <label for="needed">Options</label><br>
          <input type="checkbox" name="needed" value="flight"> Flight<br>
          <input type="checkbox" name="needed" value="hotel"> Hotel<br>
          <input type="checkbox" name="needed" value="car"> Rental Car<br>
</fieldset>
  <div id="activities" class="">
                    <label class="">Choose an Activity</label>
                    <select id="activitiesList" name="activities" class="form-control">
                    </select>
                </div>

<fieldset>
 <legend>Billing Information</legend>
   <label for="line1">Address Line 1:</label>
     <input type="text" id="line1" name="line1" class="form-control">
       <label for="line2">Address Line 2:</label>
     <input type="text" id="line2" name="line2" class="form-control">
       <label for="city">City: </label>
     <input type="text" name="city" class="form-control"><br>
       <label for="state">State: </label>
     <select name="state" id="state">
         <option value="AL">Alabama</option>
         <option value="AK">Alaska</option>
         <option value="AZ">Arizona</option>
         <option value="AR">Arkansas</option>
         <option value="CA">California</option>
         <option value="CO">Colorado</option>
         <option value="CT">Connecticut</option>
         <option value="DE">Delaware</option>
         <option value="DC">District Of Columbia</option>
         <option value="FL">Florida</option>
         <option value="GA">Georgia</option>
         <option value="HI">Hawaii</option>
         <option value="ID">Idaho</option>
         <option value="IL">Illinois</option>
         <option value="IN">Indiana</option>
         <option value="IA">Iowa</option>
         <option value="KS">Kansas</option>
         <option value="KY">Kentucky</option>
         <option value="LA">Louisiana</option>
         <option value="ME">Maine</option>
         <option value="MD">Maryland</option>
         <option value="MA">Massachusetts</option>
         <option value="MI">Michigan</option>
         <option value="MN">Minnesota</option>
         <option value="MS">Mississippi</option>
         <option value="MO">Missouri</option>
         <option value="MT">Montana</option>
         <option value="NE">Nebraska</option>
         <option value="NV">Nevada</option>
         <option value="NH">New Hampshire</option>
         <option value="NJ">New Jersey</option>
         <option value="NM">New Mexico</option>
         <option value="NY">New York</option>
         <option value="NC">North Carolina</option>
         <option value="ND">North Dakota</option>
         <option value="OH">Ohio</option>
         <option value="OK">Oklahoma</option>
         <option value="OR">Oregon</option>
         <option value="PA">Pennsylvania</option>
         <option value="RI">Rhode Island</option>
         <option value="SC">South Carolina</option>
         <option value="SD">South Dakota</option>
         <option value="TN">Tennessee</option>
         <option value="TX">Texas</option>
         <option value="UT">Utah</option>
         <option value="VT">Vermont</option>
         <option value="VA">Virginia</option>
         <option value="WA">Washington</option>
         <option value="WV">West Virginia</option>
         <option value="WI">Wisconsin</option>
         <option value="WY">Wyoming</option>
            </select><br><br>
            <label for="zip">Zip Code: </label>
            <input type="text" name="zip" id="zip" class="form-control"><br>
 </fieldset>
     <button type="submit" form="travelform" value="Submit"><strong>Submit</button>
    </form>

 </div>
  <div class="row text-center">
    </div>
  </div>
 </div>
  </body>

 <?php

 $required = array('firstname', 'lastname', 'phone', 'email', 'locations', 'depart_Date', 'return_Date');

if (isset($_POST['submit']))

{
echo "Hello, a client has submitted their information for you to review!:<br>";

echo "<br>First Name: ".$_POST['firstname']."
<br>
Middle Name: ".$_POST['middlename']."
<br>
Last Name: ".$_POST['lastname']."
<br>
Phone Number: ".$_POST['phone']."
<br>
Email: ".$_POST['email']."
<br>
Destination: ".$_POST['locations']."
<br>
Departure Date: ".$_POST['depart_Date']."
<br>
Return Date: ".$_POST['return_Date'];
}

    function emailValidation($email) {
           if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
               return 1;
           } else {
               return 0;
           }
        }

    function dateValidation($date, $format = 'Y-m-d')
        {
            $d = DateTime::createFromFormat($format, $date);
            return $d && $d->format($format) === $date;
        }

    $servername = "localhost";
    $username = 'root';
    $password = '';
    $dbname = 'TravelDB';

    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {
        die("Failed to Connect: " . $conn->connect_error);
    }

    $sql = "INSERT INTO megaTravel (FirstName, MiddleName, LastName, PhoneNumber, Email, City, DepartureDate, ReturnDate)
    VALUES ('{$_POST['firstName']}', '{$_POST['middleName']}','{$_POST['lastName']}','{$_POST['phoneNum']}', '{$_POST['Email']}',
     {$_POST['Locations']}', '{$_POST['departure_Date]}', '{$_POST['return_Date']} )";

    if ($conn->query($sql) === TRUE) {
        echo "<br><br>Success!<br>";
    } else {
        echo "<br>Error: " . $sql . "<br>" . $conn->error;
    }

    $sql = "SELECT * FROM megaTravel";
    $result = mysqli_query($conn, $sql);
    echo "<br>";
    echo "<table border='1'>";
    echo "<tr>";
    echo "<td style='text-align: center; font-weight: bold'>ID</td>","<td style='text-align: center; font-weight: bold'>Name</td>","<td style='text-align: center; font-weight: bold'>Phone</td>","<td style='text-align: center; font-weight: bold'>Email</td>","<td style='text-align: center; font-weight: bold'>Adults</td>","<td style='text-align: center; font-weight: bold'>Children</td>","<td style='text-align: center; font-weight: bold'>City</td>","<td style='text-align: center; font-weight: bold'>Travel_Date</td>","<td style='text-align: center; font-weight: bold'>Activity</td>";
    echo "</tr>";

    while ($row = mysqli_fetch_assoc($result)) { 
        echo "<tr>";
        foreach ($row as $field => $value) { 
            echo "<td>" . $value . "</td>"; 
        }
        echo "</tr>";
    }
    echo "</table>";

    $conn->close();

    ?>

0 个答案:

没有答案