【问题标题】:Best data type to store long text like news, articles.存储长文本(如新闻、文章)的最佳数据类型。
【发布时间】:2016-07-13 02:47:14
【问题描述】:

这是我在尝试存储新闻条目时遇到的问题,其中一些条目正在插入,但有些则没有。我不知道问题是否出在数据类型上。我只是复制我在互联网上找到的一些新闻并将其粘贴到我的表格中。有人可以帮我解决这个问题吗?

我的数据库结构..

未插入的新闻示例。我在 wiki 中复制此文本并将其粘贴到我的新闻内容输入中。并没有工作。

成功插入的新闻示例

这是我的添加代码。

 <?php
    include_once('connection.php');
    session_start();
   $username = ucfirst($_SESSION['username']);

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

    $title = $_POST['title'];
    $date = $_POST['date'];
    $content = $_POST['content'];
    $file=$_FILES['image']['tmp_name'];
    $image= @addslashes(file_get_contents($_FILES['image']['tmp_name']));
    $image_name= addslashes($_FILES['image']['name']);
    move_uploaded_file($_FILES["image"]["tmp_name"],"img/" . $_FILES["image"]["name"]);
    $newsimage="img/" . $_FILES["image"]["name"];



    $sql ="INSERT into news (news_title, news_date, news_content, news_image) VALUES ('$title', '$date', '$content', '$newsimage')";
    mysqli_query($con, $sql);

    echo '<div class="alert alert-success alert-dismissable" id="success-alert">';
   echo '<strong>Successfully posted!</strong>';
   echo '</div>';

  }




  ?>

【问题讨论】:

    标签: php mysql


    【解决方案1】:

    这里很少会出错。

    在发布表单数据时,您需要使用 POST 而不是 GET。

    如果数据在插入数据库之前成功发布转义文本:

    $content = mysqli_real_escape_string(stripslashes($_POST['content']));
    

    LONGTEXT 适用于较长的文本。除非您使用二进制数据(如图片等),否则您不需要 LONGBLOB

    【讨论】:

    • 我没有使用 GET 我使用 POST。
    • 我测试了你的建议,将 mysqli_real_escape_string 放到我的 news_content 中,结果成功插入,但 news_content 为空白。
    • I this you put '(同位词)这是行不通的。你可以替换你的字符串。
    • 对不起先生?你是什​​么意思?我该怎么办?
    • 你不能放这个字符串;示例:谷歌是最好的搜索引擎。但是你可以把谷歌说成是一个最好的搜索引擎。你不能把'这个值
    【解决方案2】:

    我通过将$content = $_POST['content']; 更改为$content = mysqli_real_escape_string($con,$_POST['content']); 解决了这个问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-20
      • 2011-12-28
      • 2014-10-03
      • 2014-05-23
      • 1970-01-01
      • 2012-01-01
      • 2018-09-13
      相关资源
      最近更新 更多