无法在DB中插入

时间:2017-03-26 13:51:34

标签: php html mysql mysqli insert

PHP代码:

session_start();

include'include/connect.php';
include'include/header.php';

if(isset($_POST["helpline"])) {      
  $feedback=$_POST['feedback'];
  $email=$_POST['email'];

  {
    $sql= mysqli_query($connection,"SELECT * FROM tbl_users where id='".$_SESSION['id']."'");
    $row= mysqli_fetch_array($sql);
    $stmt = mysqli_query($connection,"INSERT INTO helpcenter set uid='".$_SESSION['id']."',feedback='".$feedback."',email='".$email."'");
  }

  if($stmt) {
    echo "hello world";
  }
}

HTML表单:

<form action="" method="post">
  <label for="email">Email</label>
  <input type="text" id="email" name="email" placeholder="Enter your Email...">
  <label for="subject">Subject</label>
  <textarea id="subject" name="feedback" placeholder="Write something.." style="height:160px"></textarea>
  <button type="submit" class="butn" name="helpline">POST</button>
</form>

我正在尝试将数据插入到mysql数据库中。我无法找出我在这里做错了什么。

1 个答案:

答案 0 :(得分:-2)

请检查SQL语法。

您的插入内容应为:

$stmt = mysqli_query($connection,"INSERT INTO helpcenter (uid, feedback, email) VALUES  (".$_SESSION['id'].", ".$feedback.", ".$email.")";