【问题标题】:I want to insert the large text through comment box. How can I do this in PHP?我想通过评论框插入大文本。我怎样才能在 PHP 中做到这一点?
【发布时间】:2019-05-23 10:06:14
【问题描述】:

我试图在表单的评论框中提交很长的消息(比如超过 2000 封信)。但得到“评论尚未提交”。请检查以下代码:

我已将数据库中的注释类型更改为 TEXT、MEDIUMTEXT 和 LONGTEXT,但没有任何效果。它仍然显示“评论尚未提交”。

<?php
    if(isset($_POST['submit']))
    {
        $cs_name = $_POST['name'];
        $cs_email = $_POST['email'];
        $cs_comment = $_POST['comment'];
        $cs_image = implode(',', $_FILES['image']['name']);
        $cs_images = $_FILES['image']['name'];
        $cs_image_tmp =  $_FILES['image']['tmp_name'];
        $cs_image_type = $_FILES['image']['type'];
        $cs_rating = $_POST['rating'];
        $cs_date = time();
        if(empty($cs_name) or empty($cs_email) or empty($cs_comment))
        {
            $error_msg = "All (*) feilds are compulsary";
        }  
        else
        {
            $cs_query = "INSERT INTO `comments` (`id`, `date`, `name`, 
            `username`, `comp_id`, `email`, `image`, `comment`, 
            `rating`,`status`, `type`) VALUES (NULL, '$cs_date', '$cs_name', 
            'user', '$comp_id', '$cs_email', 
            '$cs_image', '$cs_comment', '$cs_rating', 'pending', 'C')";
            if(mysqli_query($con, $cs_query))
            {
                $msg = "Comment Submitted and waiting for Approval";
                for($i=0; $i<=count($cs_image_tmp)-1;$i++)
                {
                    move_uploaded_file($cs_image_tmp[$i], 
                        "admin/images/uploded/$cs_images[$i]");
                }
                header('Location: companies.php?comp_id='.$comp_id.'');
                exit();
            }
            else
            {
                $error_msg = "Comment has not be submitted";
            }
        }
    }
?>

它应该提交一个很长的评论(成功说超过2000个字母并将其存储在数据库中。

【问题讨论】:

  • 有什么错误吗?
  • 你好,@DeepakTyagi 首先你回显你的插入查询,然后复制你的查询并粘贴到 SQL 数据库表中并检查。
  • @TarangP 查看我发送短消息时没有错误。但是当我插入大文本时,else 查询被执行(即尚未提交评论)。
  • @SubhashPatel 您好,感谢您的评论。看到查询中没有错误,它工作正常,但是当我尝试在评论框中发送长文本时,它会执行没有提交评论的 else 部分。但对于短文本来说,两三行它工作正常。
  • 而不是$error_msg = "Comment has not be submitted"; 尝试printf("Query failed: " . mysqli_error($link));die("Query failed: " . mysqli_error($link)); 其中一个应该输出更多信息的mysqli错误

标签: php mysql mysqli phpmyadmin


【解决方案1】:

是的,我得到了答案。我在 move_uploded_files 的 for 循环之前添加了一个 if 条件。那是造成问题。

    if(!empty($cs_images)){
        for($i=0; $i<=count($cs_image_tmp)-1;$i++){
        move_uploaded_file($cs_image_tmp[$i], "admin/images/uploded/$cs_images[$i]");
            }
        }

非常感谢你们的cmets。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-09
    • 2018-10-05
    • 1970-01-01
    • 2012-08-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多