PHP无法处理大文本

时间:2015-12-04 23:27:58

标签: php html process

我正在开发一个开发网站,该网站涉及用户将他们喜欢的书籍内容发布到网页上,所有数据都存储在数据库中并显示在网站上。 然而,每当我尝试使用我创建的表单和处理表单的php脚本发布大段落时,它不会给出任何错误,但它也不会将值存储到数据库中。如果要处理的内容很短,它可以正常工作。请帮我,代码如下。任何建议将不胜感激。

<?php
$hostname = "localhost";
$username = "root";
$password = "";
$database = "library";
$conn = mysql_connect($hostname,$username,$password)or die('Cannot connect');
mysql_select_db("library", $conn);
?>

<?php
$title = $_POST['title'];
$author = $_POST['author'];
$content = strval($_POST['content']);
$description = $_POST['description'];
$category = $_POST['category'];

if (isset($title) && !empty($title)){
    $sql = "INSERT INTO books(title,author,description,content,category) VALUES('$title','$author','$description','$content','$category')";
    mysql_query($sql);
    echo 'Successfully Added the book'."<a href='/'><br>Check it out here<a>";
}
else{
    echo 'Title is missing';
}
?>

感谢。

1 个答案:

答案 0 :(得分:0)

首先,请使用PDO - 如果没有,请至少使用mysql_real_escape_string转义您的POST参数:

$title = mysql_real_escape_string($_POST['title']);
$author = mysql_real_escape_string($_POST['author']);
$content = mysql_real_escape_string($_POST['content']);
$description = mysql_real_escape_string($_POST['description']);
$category = mysql_real_escape_string($_POST['category']);

此外,strval不足以逃避$_POST['content']以便在SQL查询中使用,mysql_real_escape_string(如上所述)更好。

解决后:

可能失败的两个可能的地方(我能想到)

  • 您是否达到了PHP内存限制?检查服务器的错误日志以查看,您可以增加内存限制。

  • 您确定在MySQL中保存数据的列可以存储这么多数据吗?如果不是,您应该收到MySQL错误(请参阅http://php.net/manual/en/function.mysql-error.php

相关问题