Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/268.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Textarea不在数据库中保存文本_Php_Html_Mysql - Fatal编程技术网

Php Textarea不在数据库中保存文本

Php Textarea不在数据库中保存文本,php,html,mysql,Php,Html,Mysql,我有一个textarea问题,无法使用post方法获取数据。 我通过phpmyadmin检查了我的数据库,但这段代码没有保存任何内容。我做错了什么?表单操作页面与此页面相同。 数据库连接: <?php $connection = mysqli_connect('localhost', 'root', '', 'test_db'); if($connection == false) { echo "Could not connect to database"; echo mysq

我有一个textarea问题,无法使用post方法获取数据。 我通过phpmyadmin检查了我的数据库,但这段代码没有保存任何内容。我做错了什么?表单操作页面与此页面相同。 数据库连接:

<?php
$connection = mysqli_connect('localhost', 'root', '', 'test_db');
if($connection == false) {
   echo "Could not connect to database";
   echo mysqli_connect_error;
   exit();
}
?>

以下是php代码:

<?php
date_default_timezone_set('UTC');

if (isset($_POST['comment'])) {
    $commentText = htmlspecialchars($_POST['comment']);
    $commentPubDate = htmlspecialchars(date("d.m.Y H:i:s"));
    mysqli_query($connection, "INSERT INTO `identify` (comments, compubdate) VALUES ('$commentText','$commentPubDate')");
}

$allComments = mysqli_query($connection, "SELECT * FROM `comments`");
$allCommentsPubDate = mysqli_query($connection, "SELECT * FROM `compubdate");

print_r(mysqli_fetch_array($allComments));
print_r(mysqli_fetch_array($allCommentsPubDate));
?>
和html代码:

<form method="post" action="index.php">
    <textarea rows="5" cols="80" id="comment-input" placeholder="Leave a comment..." name="comment"></textarea>
    <input type="submit" id="comment-submit">
</form>
下面是我得到的错误:

警告:mysqli_fetch_数组期望参数1为mysqli_结果,布尔值在第62行的/Library/WebServer/Documents/index.php中给出


我的问题不同,因为我的INSERT错误,而不是SELECT错误。选择“正常工作”。

您在插入查询中使用的是单引号,可能您必须从值中删除此“符号”,希望这对您有所帮助

if (isset($_POST['comment'])) {
    $commentText = htmlspecialchars($_POST['comment']);
    $commentPubDate = htmlspecialchars(date("d.m.Y H:i:s"));
    mysqli_query($connection, "INSERT INTO `identify` (comments, compubdate) VALUES ('".$commentText."','".$commentPubDate."')");
}

在我看来不错;你确定你连到数据库了吗?那评论的价值是什么?有撇号吗?在查询上使用mysqli_error$connection;它显示了什么?你们不应该包括你们的数据库连接文件吗?数据库工作正常,我已经在页面上方注册了。我没有分析错误,但当我只输入符号注释时,它会重新加载页面并保存NULL。包含的db连接$allCommentsPubDate=mysqli_query$connection,从'compubdate'中选择*;在'CompubDate'之后结束你的反向报价这对操作没有帮助。不是我的DVthough@Akin否决票是我的;Amit认为这是PHP;不是,它是MySQL,必须引用字符串文本。答案不正确。说得好@Fred ii-。我注意到了编辑,使用了“$var”。-这可能会有什么不同$var'也做同样的事情。