$body = $_POST['post'];
$submit = $_POST['submit'];
$date = date("Y-m-d");
require('php/connect.php');
if($submit)
{
$query = mysql_query("INSERT INTO news (`id`, `body`, `date`) VALUES (NULL, '".$body."', '".$date."')");
header("Location: index.php");
}我不明白为什么这不工作,我直接从PHP我的管理员在写了一行模拟后,它仍然不能工作,有人能帮我吗?
发布于 2011-04-22 23:18:15
您绝对应该使用mysql_real_escape_string对输入值进行转义
使用mysql_error,您可以打印出一条错误消息,但您需要将连接标识符作为参数。
发布于 2011-04-22 23:19:32
我只建议处理mysql错误
$query = mysql_query("INSERT INTO news (`id`, `body`, `date`) VALUES (NULL, '".$body."', '".$date."')")
or trigger_error(mysql_error());如果id是不能为null的主键
您应该使用函数对用户输入进行转义。
如果我在您的$body输入中输入"that's it "值,您的查询将失败。
发布于 2011-04-22 23:27:11
注释掉标头(“Location: index.php");,并在查询代码的末尾追加或消亡(mysql_error());,这将显示出哪里出了问题。在将用户输入插入数据库之前,还应该对其进行"mysql_real_escape_string“操作。
$body = mysql_real_escape_string($_POST['post']);
$submit = $_POST['submit'];
$date = date("Y-m-d");
require('php/connect.php');
if($submit)
{
$query = mysql_query("INSERT INTO news (`id`, `body`, `date`) VALUES (NULL, '$body', '$date')") or die(mysql_error());
//header("Location: index.php");
}https://stackoverflow.com/questions/5756819
复制相似问题