doucong7963 2016-07-13 02:47
浏览 531
已采纳

存储长文本的最佳数据类型,如新闻,文章。

This is my problem when im trying to store news entry some of those entries are inserting but some are not. I don't know if the problem is on the data type. Im just copying some news i found in internet and paste it to my form. Can someone help me about this?

my database structure.. enter image description here

sample of the news that are not inserting. i copy this text in the wiki and paste it to my news content input. and didnt work. enter image description here

sample of news that successfuly inserted enter image description here

here is my code for adding.

 <?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>';

  }




  ?>
  • 写回答

2条回答 默认 最新

  • duannai5858 2016-07-13 23:18
    关注

    I solved it by changing the $content = $_POST['content']; to $content = mysqli_real_escape_string($con,$_POST['content']);

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥100 求数学坐标画圆以及直线的算法
  • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 自己瞎改改,结果现在又运行不了了
  • ¥15 链式存储应该如何解决
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站