Unable to save large text in mysql thru php

 ̄綄美尐妖づ 提交于 2019-12-23 13:33:37

问题


$query="INSERT INTO `ARTICLES` (`TITLE`, `BY`, `IN`, `POST`) 
VALUES('". $title ."', '". $by ."', '". $in ."', '". $_POST['post'] ."')";

This code is able to save small length text but not large. The datatype for the POST field is longtext. Also if i insert data thru phpmyadmin, it gets saved.


回答1:


$query="INSERT INTO ARTICLES (TITLE, BY, IN, POST) VALUES('$title', '$by', '$in', '". $_POST['post'] ."')";

Use this query, and modify the database field's property to BLOB text using PHPmyAdmin.

I works for me when i need to insert large contents.




回答2:


like Felix kling says you need to escape your post data because maybe there are some quotes in the text you try to save but it will prevent your query to run properly and it is also a major security risk not to escape before sending to the database.

$post = mysql_real_escape_string($_POST['post']);

$query="INSERT INTO `ARTICLES` (`TITLE`, `BY`, `IN`, `POST`) 
VALUES('". $title ."', '". $by ."', '". $in ."', '". $post ."')";

also make sure you've set the POST column to text in phpmyadmin. Because if you didn't prepare enough space it won't save to the database.




回答3:


To insert data in a Database always use a PreparedStatement! Never trust the users input!




回答4:


I suggest you use mysqli_stmt::send_long_data : http://php.net/manual/en/mysqli-stmt.send-long-data.php . There are some good examples in manual/comments.



来源:https://stackoverflow.com/questions/6175837/unable-to-save-large-text-in-mysql-thru-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!