PHP,HTML,MySql表单拒绝发布

时间:2016-12-17 03:56:23

标签: php html forms

我做了很多表格,但由于某些未知的原因,我无法让这个表现出来。我点击提交,它只是停留在同一页面上,所有输入都是空的。也许一双新鲜的眼睛会看到我没有的东西。我已经尝试将PHP放在一个单独的文件中,对输入语句和其他所有内容进行双/三检查,但无论如何都看不到它。

这是表格:

CREATE TABLE `store_orders` (
  `id` int(11) NOT NULL,
  `order_date` varchar(70) NOT NULL,
  `order_first_name` varchar(50) NOT NULL,
  `order_last_name` varchar(50) NOT NULL,
  `order_address` varchar(255) NOT NULL,
  `order_city` varchar(50) NOT NULL,
  `order_state` char(50) NOT NULL,
  `order_zip` varchar(10) NOT NULL,
  `order_tel` varchar(25) NOT NULL,
  `order_email` varchar(100) NOT NULL,
  `cc_type` varchar(30) NOT NULL,
  `cc_number` int(16) NOT NULL,
  `cc_expmonth` int(2) NOT NULL,
  `cc_expyear` int(2) NOT NULL,
  `cc_cvc` int(3) NOT NULL
)

这是页面顶部的PHP:

<?php
session_start();
//connect to database
$con = mysqli_connect("localhost", $username, #pw, $db);




$error = false;

if (isset($_POST['checkout'])) {
    $datetime = mysqli_real_escape_string($con, $_POST['order_date']);
    $fname = mysqli_real_escape_string($con, $_POST['order_first_name']);
    $lname = mysqli_real_escape_string($con, $_POST['order_last_name']);
    $address = mysqli_real_escape_string($con, $_POST['order_address']);
    $city = mysqli_real_escape_string($con, $_POST['order_city']);
    $state = mysqli_real_escape_string($con, $_POST['order_state']);
    $zip = mysqli_real_escape_string($con, $_POST['order_zip']);
    $phone = mysqli_real_escape_string($con, $_POST['order_tel']);
    $email = mysqli_real_escape_string($con, $_POST['order_email']);
    $cardtype = mysqli_real_escape_string($con, $_POST['cc_type']);
    $cardnumber = mysqli_real_escape_string($con, $_POST['cc_number']);
    $cardmonth = mysqli_real_escape_string($con, $_POST['cc_expmonth']);
    $cardyear = mysqli_real_escape_string($con, $_POST['cc_expyear']);
    $cardcvc = mysqli_real_escape_string($con, $_POST['cc_cvc']);

    $fname = stripslashes($fname);
    $lname = stripslashes($lname);
    $address = stripslashes($address);
    $city = stripslashes($city);
    $zip = stripslashes($zip);
    $phone = stripslashes($phone);
    $email = stripslashes($email);
    $cardtype = stripslashes($cardtype);
    $cardnumber = stripslashes($cardnumber);
    $cardmonth = stripslashes($cardmonth);
    $cardmonth = stripslashes($cardmonth);
    $cardyear = stripslashes($cardyear);
    $cardcvc = stripslashes($cardcvc);


    if (!preg_match("/^[a-zA-Z ]+$/",$fname)) {    /* name can contain only alpha characters and space */
        $error = true;
        $name_error = "Name must contain only letters"; }
    if (!preg_match("/^[a-zA-Z ]+$/",$lname)) {    /* name can contain only alpha characters and space */
        $error = true;
        $name_error = "Name must contain only letters"; }
    if (!preg_match("/^[a-zA-Z-0-9 ]+$/",$address)) {    /* letters and numbers */
        $error = true;
        $user_name_error = "Address can contain only letters and numbers"; }
    if (!preg_match("/^[a-zA-Z-0-9 ]+$/",$city)) {    /* letters and numbers */
        $error = true;
        $user_name_error = "City can contain only letters and numbers"; }
    if(!filter_var($email,FILTER_VALIDATE_EMAIL)) {    /* will accept only email addresses */
        $error = true;
        $email_error = "Please Enter Valid Email ID"; }


    if (!$error) {
    if(mysqli_query($con, "INSERT INTO store_orders(order_date, order_first_name, order_last_name, order_address, order_city , order_state, order_zip, order_tel, order_email, cc_type, cc_number, cc_expmonth, cc_expyear, cc_cvc ) VALUES('".$datetime."','".$fname."','".$lname."','".$address."','".$city."','".$state."','".$zip."','".$phone."','".$email."','".$cardtype."','".$cardnumber."','".$cardmonth."','".$cardyear."','".$cardcvc."')")); 
    header('Location: checkout-view.php');
    } else {
            $errormsg = "Error completing form...Please try again!";    /* if register is not successful */
        }
    }



?>

这是同一页面上的表格......

<!doctype html>
<html>
<!-- InstanceBegin template="/Templates/index.dwt" codeOutsideHTMLIsLocked="false" -->

<head>
</head>

<body style="background-color: #f9ecf2;">

  <div class="container">

    <div class="col-md-8 col-sm-8 grad" style="background-color:  ; margin-right: 0px; margin-left: 0px;  border-bottom-style: solid; border-bottom-color: #4d004d; border-bottom-width: 1px; padding-left: 0px;">
      <!-- begin middle column -->
      <!-- InstanceBeginEditable name="EditRegion3" -->
      <div style='width: 85%; margin-left: auto; margin-right: auto;'>
        <br>
        <br>
        <br>
        <form role="form" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="checkout">
          <table width="100%" border="0" class="responsive">
            <tr>
              <td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Date - Time</b5>
              </td>
              <td>
                <b3 style="font-size: 12pt;">
                  <input name="order_date" id="order_date" type="text" value="<?php echo date('m/d/y');?>" />
                </b3>
              </td>
            </tr>

            <tr>
              <td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">First Name:</b5>
              </td>
              <td>
                <b3 style="font-size: 12pt;">
                  <input name="order_first_name" id="order_first_name" type="text" size="50" maxlength="50" required="required" />
                </b3>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Last Name:</b5>
              </td>
              <td>
                <b3 style="font-size: 12pt;">
                  <input name="order_last_name" id="order_last_name" type="text" size="50" maxlength="40" required="required" />
                </b3>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Address:</b5>
              </td>
              <td>
                <b3 style="font-size: 12pt;">
                  <input name="order_address" id="order_address" type="text" size="50" maxlength="255" required="required" />
                </b3>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">City:</b5>
              </td>
              <td>
                <b3 style="font-size: 12pt;">
                  <input name="order_city" id="order_city" type="text" size="50" maxlength="50" required="required" />
                </b3>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" width="30%" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Select State:</b5>
              </td>
              <td style=" padding-top: 5px;">
                <b3 style="font-size: 12pt;">
                  <select name="order_state" id="order_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>
                </b3>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Zip Code:</b5>
              </td>
              <td style=" padding-top: 5px;">
                <b3 style="font-size: 12pt;">
                  <input name="order_zip" id="order_zip" type="text" size="50" maxlength="10" required="required" />
                </b3>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Phone:</b5>
              </td>
              <td style=" padding-top: 5px;">
                <b3 style="font-size: 12pt;">
                  <input name="order_tel" id="order_tel" type="text" size="50" maxlength="25" required="required" />
                </b3>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Email Address:</b5>
              </td>
              <td style=" padding-top: 5px;">
                <b3 style="font-size: 12pt;">
                  <input name="order_email" type="email" id="order_email" size="50" maxlength="100" required="required" />
                </b3>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Select Card Type:</b5>
              </td>
              <td style=" padding-top: 5px; font-size: 24pt; color: #4d004d">
                <p>
                  <b5>
                    <img src="img/cc-mastercard.png" width="75" height="49" alt="" />
                    <input type="radio" name="cc_type" value="Mastercard">
                    <img src="img/cc-visa.png" width="75" height="49" alt="" />
                    <input type="radio" name="cc_type" value="Visa">
                    <img src="img/cc-american-express.png" width="75" height="49" alt="" />
                    <input type="radio" name="cc_type" value="American Express">
                    <img src="img/cc-paypal.png" width="75" height="49" alt="" />
                    <input type="radio" name="cc_type" value="PayPal">
                  </b5>
                </p>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Card Number:</b5>
              </td>
              <td style=" padding-top: 5px;">
                <b3 style="font-size: 12pt;">
                  <input name="cc_number" type="integer" id="cc_number" size="50" maxlength="16" required="required" />
                </b3>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">Expiration:</b5>
              </td>
              <td style=" padding-top: 5px;">
                <b3 style="font-size: 12pt;">
                  <input name="cc_expmonth" type="integer" id="cc_expmonth" size="2" maxlength="2" required="required" /><span Style='font-size: 18pt; color: #4d004d'><b3>&nbsp/&nbsp</span>
                </b3>
                <input name="cc_expyear" type="integer" id="cc_expyear" size="2" maxlength="2" required="required" />
                </b3>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;">
                <b5 style="text-align: right; line-height: 80%; font-size: 16pt; color: black;">CVC Code:</b5>
              </td>
              <td style=" padding-top: 5px;">
                <b3 style="font-size: 12pt;">
                  <input name="cc_cvc" type="integer" id="cc_cvc" size="3" maxlength="3" required="required" />
                </b3>
              </td>
            </tr>
            <tr>
              <td align="right" valign="top" style="padding-left: 15px; padding-right: 10px; padding-top: 10px;"></td>
              <td style=" padding-top: 5px;">
                <b5 style="font-size: 12pt;">
                  <input name="submit" type="submit" value="Submit" /><span>&nbsp&nbsp&nbsp</span>
                  <input name="reset" type="reset" value="Reset" />
                </b5>
              </td>
            </tr>


          </table>
        </form>

      </div>
      <br>
      <br>
      <br>
      <!-- InstanceEndEditable -->
    </div>
    <!-- end middle column -->

</body>
<!-- InstanceEnd -->

</html>

连接是对的。我有一个小时的时间来完成这项任务,在午夜(美国东部时间),学期结束了。今年秋天我在其他一切事情上取得了100分的好处......在过去的一年或更长时间里我创造了无数的形式,从来没有出现问题......

1 个答案:

答案 0 :(得分:0)

将提交按钮的名称更改为&#34;结帐&#34;并删除名称=&#34;结帐&#34;从形式。