开发者

Unable to save large text in mysql thru php

$query="INSERT INTO `ARTICLES` (`TITLE`, `BY`, `IN`, `P开发者_如何学编程OST`) 
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.


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.


$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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜