我正在尝试将一些数据发送到数据库,但是脚本消息正在发送,但数据不在数据库中

时间:2019-07-16 04:29:40

标签: php html css mysql

我正在尝试向数据库发送一些值,但是它没有给出任何错误或警告,并且脚本随消息一起弹出,但是表为空。我尝试了这些东西。我正在尝试编辑模板,并将编辑后的数据发送到具有隐藏值的数据库,该值是模板ID,这里有四个模板,但是这里只有一个。

template.php

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="css/templateStyle.css">
    <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
      <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  </head>
  <body>

      <form name="form1" action="addToCart.php" method="post" >
    <div class="business-card middle">
      <div class="front">

              <input type="hidden" value="1" name="field0" />
        <input type="text" name="field1" />
        <!--<span>Web Designer field2</span>-->
        <ul class="contact-info">
          <li>
            <i class="fas fa-mobile-alt"></i> <input type="text" name="field3" />
          </li>
          <li>
            <i class="far fa-envelope"></i> <input type="text" name="field4" />
          </li>
          <li>
            <i class="fas fa-map-marker-alt"></i> <input type="text" name="field5" />
          </li>
        </ul>
          <input type="submit" class="btn btn-success" value="Add to Cart" name="cart"/> 
              </form>
      </div>
      <div class="back">
        <span>Double Click to Edit</span>
      </div>
    </div>



    <script>
      $(".business-card").dblclick(function(){
        $(".business-card").toggleClass("business-card-active");
      });
    </script>

  </body>
</html>

addtocart.php

<?php

include 'config.php';

{
    if (isset($_POST["cart"])){

        $field0 = $_POST["field0"];
        $field1 = $_POST["field1"];
        //$field2 = $_POST["field2"];
        $field3 = $_POST["field3"];
        $field4 = $_POST["field4"];
        $field5 = $_POST["field5"];

    if (empty($field0)||empty($field1)||empty($field3)||empty($field4)||empty($field5)){
        echo '<script>alert("Please Complete all the data")</script>';
    }else{
        $insert = mysqli_query($conn, "INSERT INTO 'template' ('field0','field1','field3','field4','field5') VALUES ('$field0','$field1','$field3','$field4','$field5')");
        echo '<script>alert("Order is added to cart")</script>';
    }
}
?>

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Cart</title>
</head>

<body>
    <?php } ?>
</body>
</html>

0 个答案:

没有答案