php - 我的插入查询失败了什么?

标签 php html mysql forms

我有一个表单可以通过帖子提交到我数据库中的表中。然而,每当我点击提交时,就会说失败。我删除了几个验证脚本,以尝试找出表单未提交的原因。

我使用 mysqli_query 检查了许多有关 INSERT 的已回答问题,但似乎没有人回答我的问题。我知道 HTML 结构可能很差,这只是为了让脚本首先正常工作。其实并不复杂,我不明白这里出了什么问题。

我有一个注册表,我正在处理的网站上的其他表格都工作正常,正确更新了表格的日期。不知道我在这里缺少什么。

<?php
include('db.php');


$event_name='';
$place='';
$time='';
$date='';
$description=''; 



$event_name=strip_tags($_POST['event_name']);
$place=strip_tags($_POST['place']);
$time=strip_tags($_POST['time']);
$date=strip_tags($_POST['date']);
$description=strip_tags($_POST['event_description']);


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

    $query = "INSERT INTO user_posts (title, location, time, date, description)"; 

    $query .= "VALUES ($event_name','$place','$time','$date','$description')";

    if (mysqli_query($connection, $query)) {

        echo "<h2> your post has been submitted </h2>";
        }
    else { 
        die('failure');     
    }
    }

和 html 表单

    <body>
   <div class="box-1">
   <form action="create_post_script.php" method="post" id="event_form">

   <div class="box-2">
   <input type="text" name="event_name" placeholder="event title" />   
   </div>

   <div class="box-3">
     <input type="text" name="place" placeholder="location" id="box-3" />
   </div>

    <div class="box-4">
       <input type="time" name="time"  id="box-4" /> 
    </div>

    <div class="box-4">
       <input type="date" name="date" id="box-4" />  
    </div>

    <div class="box-5">
     <h4> <center> ... </center> </h4>
    <textarea class="text-area" name="event_description" id="event_form" >
    </textarea>
    <input type="submit" value="submit" name="submit" placeholder="submit"/>     
    </div>

    <div class="box-6">
     <div class="box-7">       
     <h4>  </h4>
      </div>
      </div> 

     </form>
     </div>

当我点击提交时,结果页面确认我的连接并显示“失败”,这是因为我有 <text-area> 的提交输入字段的方式吗? ?

最佳答案

试试这个

$query = "INSERT INTO user_posts (title, location, time, date, description) "; 

$query .= "VALUES ('$event_name','$place','$time','$date','$description')";

关于php - 我的插入查询失败了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38800629/

相关文章:

php - Doctrine 只选择第一行数据,无论如何

html - bootstrap 下拉列表的大小错误。没有反应如何解决?

html - 无法理解我的宽度值

PHP mySQLi : if "&&" protocol and mySQLi statement error checking

javascript - jQuery "Can only call NodeList.item on instances of nodelist"

php - 将 id css 添加到 Zend 导航菜单中的第一个 ul

php - 如何解决 GCM 1000 条消息限制,想要将消息发送到 10000 条数据库?

javascript - 通过 javascript 编辑内容后,将插入符位置保持在 contenteditable

mysql - 远程数据库连接问题

php - 为 PDF 文件生成唯一的下载链接