无法在phpmyAdmin中保存数据

时间:2016-07-05 08:19:25

标签: javascript php html mysql css

问题:  您好,我的提交表单有问题。我已经创建了一个数据库,我也创建了一个表。当我已填写表单时,单击“提交”按钮,然后检查phpmyAdmin。它没有显示我已提交的详细信息。

这是我的php代码包括sql connect(reserve.php)

<?php 
    if($_POST['formSubmit'] === "Submit")
    {
        $errorMessage = "";

        if(empty($_POST['formName']))
        {
            $errorMessage .= "<li> You forgot to enter your name! </li>";
        }


        //Doesnt Have List
        $varName = $_POST['formName'];
        $varEmail = $_POST['formEmail'];
        $varPhone = $_POST['formPhone'];
        $varStreet = $_POST['formStreet'];
        $varNumber = $_POST['formNumber'];
        $varCity = $_POST['formCity'];
        $varPostCode = $_POST['formPostCode'];
        $varCountry = $_POST['formCountry'];
        //Have List
        $varPeople = $_POST['formPeople'];
        $varTables = $_POST['formTables'];
        $varTime = $_POST['formTime'];
        $varComment = $_POST['formComment'];

        if(empty($errorMessage))
        {
            //Sql Connect
            $db = mysql_connect ('sql999.byethost9.com','b9_9999999','password');
            if(!$db) die("Error connecting to MySQL database.");
            mysql_select_db('b9_9999999_database',$db);

            $sql = "INSERT INTO form2 (Name, Email, Phone, Street, Number, City, PostCode, Country, People, Tables, Time, Comment) VALUES (".
            //Doesnt Have List Dropdown
            PrepSQL($varName) . ", ".
            PrepSQL($varEmail) . ", ".
            PrepSQL($varPhone) . ", ".
            PrepSQL($varStreet) . ", ".
            PrepSQL($varNumber) . ", ".
            PrepSQL($varCity) . ", ".
            PrepSQL($varPostCode) . ", ".
            PrepSQL($varCountry) . ", ".
            //Have List Dropdown
            PrepSQL($varPeople) . ", ".
            PrepSQL($varTables) . ", ".
            PrepSQL($varTime) . ", ".
            PrepSQL($varComment) . ") ";
            mysql_query($sql);

            header('Location:thankyou.html');
            exit();
              }
        }

        //function:PrepSQL()
        //use stripslashes and mysql_real_escape_string PHP functions
        //tosanitize a string for use in an SQL query
        //
        //also puts single quotes around the string
        //
        function PrepSQL($value)
        {
            //Stripslashes
            if(get_magic_quotes_gpc())
            {
                $value = stripslashes($value);
            }

            //Quote
            $value = "'" . mysql_real_escape_string($value) . "'";

            return($value);
        }
    ?>

这是我的表格代码:

<html>
<?php include("reserve.php"); ?>
<body>
.......

<form action="<?php
 echo htmlentities($_SERVER['PHP_SELF']); ?>" method="post">
  <!-- PHP--> 
  <!--  General -->
  <div class="form-group">
    <h2 class="heading">Booking & contact</h2>
    <div class="controls">
      <input type="text" id="name" class="floatLabel" name="name" value="<?= $varName;
    ?>" />
      <label for="name">Name</label>
    </div>
    <div class="controls">
      <input type="text" id="email" class="floatLabel" name="email" value="<?= $varEmail;
    ?>" />
      <label for="email">Email</label>
    </div>
    <div class="controls">
      <input type="tel" id="phone" class="floatLabel" name="phone" value="<?= $varPhone;
    ?>" />
      <label for="phone">Phone</label>
    </div>
    <div class="grid">
      <div class="col-2-3">
        <div class="controls">
          <input type="text" id="street" class="floatLabel" name="street" value="<?= $varStreet;
    ?>" />
          <label for="street">Street</label>
        </div>
      </div>
      <div class="col-1-3">
        <div class="controls">
          <input type="number" id="street-number" class="floatLabel" name="street-number" value="<?= $varNumber;
    ?>" />
          <label for="street-number">Number</label>
        </div>
      </div>
    </div>
    <div class="grid">
      <div class="col-2-3">
        <div class="controls">
          <input type="text" id="city" class="floatLabel" name="city" value="<?= $varCity;
    ?>" />
          <label for="city">City</label>
        </div>
      </div>
      <div class="col-1-3">
        <div class="controls">
          <input type="text" id="post-code" class="floatLabel" name="post-code" value="<?= $varPostCode;
    ?>" />
          <label for="post-code">Post Code</label>
        </div>
      </div>
    </div>
    <div class="controls">
      <input type="text" id="country" class="floatLabel" name="country" value="<?= $varCountry;
    ?>" />
      <label for="country">Country</label>
    </div>
  </div>
  <!--  Details -->
  <div class="form-group">
    <h2 class="heading">Details</h2>
    <div class="grid">
      <div class="col-1-4 col-1-4-sm">
        <div class="controls">
          <input type="date" id="arrive" class="floatLabel" name="arrive" value="<?php
 echo date('Y-m-d'); ?>">
          <label for="arrive" class="label-date"><i class="fa fa-calendar"></i>&nbsp;&nbsp;Arrive</label>
        </div>
      </div>
    </div>
    <div class="grid">
      <div class="col-1-3 col-1-3-sm">
        <div class="controls"> <i class="fa fa-sort"></i>
          <select class="floatLabel">
            <option value="blank"></option>
            <option value="1" <?php if ($varPeople === "Less than 5")    echo ("selected=\"selected\""); ?>>Less than 5</option>
            <option value="2" <?php if ($varPeople === "More than 5")    echo ("selected=\"selected\""); ?>>More than 5</option>
            <option value="3" <?php if ($varPeople === "More than 10")    echo ("selected=\"selected\""); ?>>More than 10</option>
          </select>
          <label for="fruit"><i class="fa fa-male"></i>&nbsp;&nbsp;People</label>
        </div>
      </div>
      <div class="col-1-3 col-1-3-sm">
        <div class="controls"> <i class="fa fa-sort"></i>
          <select class="floatLabel">
            <option value="blank"></option>
            <option value="deluxe" <?php if ($varTables === "Indoor")    echo ("selected=\"selected\""); ?>>Indoor</option>
            <option value="Zuri-zimmer" <?php if ($varTables === "Outdoor")    echo ("selected=\"selected\""); ?>>Outdoor</option>
            <option value="Zuri-zimmer" <?php if ($varTables === "VIP Room")    echo ("selected=\"selected\""); ?>>VIP Room</option>
          </select>
          <label for="fruit">Tables</label>
        </div>
      </div>
      <div class="col-1-3 col-1-3-sm">
        <div class="controls"> <i class="fa fa-sort"></i>
          <select class="floatLabel">
            <option value="single-bed" <?php if ($varTime === "Breakfast")    echo ("selected=\"selected\""); ?>>Breakfast</option>
            <option value="double-bed" <?php if ($varTime === "Lunch")    echo ("selected=\"selected\""); ?>>Lunch</option>
            <!-- Add "selected >Lunch" when not using php code -->
            <option value="double-bed" <?php if ($varTime === "Dinner")    echo ("selected=\"selected\""); ?>>Dinner</option>
          </select>
          <label for="fruit">Time</label>
        </div>
      </div>
    </div>
    <div class="grid">
      <p class="info-text">Please describe your needs e.g. Annual Dinner, Party</p>
      <br>
      <div class="controls">
        <textarea name="comments" class="floatLabel" id="comments"><?= $varComment;
    ?>
</textarea>
        <label for="comments">Comments</label>
      </div>
      <button type="submit" value="Submit" class="col-1-4">Submit</button>
    </div>
  </div>
  <!-- /.form-group -->
</form>

....
</body>
</html>

1 个答案:

答案 0 :(得分:0)

您的表单字段名称与您的serve.php名称字段不匹配。您更新的代码应为

# Sets the default security model of the Apache2 HTTPD server. It does
# not allow access to the root filesystem outside of /usr/share and /var/www.
# The former is used by web applications packaged in Debian,
# the latter may be used for local directories served by the web server. If
# your system is serving content from a sub-directory in /srv you must allow
# access here, or in any related virtual host.
<Directory />
    Options FollowSymLinks
    AllowOverride All
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride All
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

这将解决您的问题