页面上的输出很好,没有错误或警告。它似乎应该将值插入数据库,但它没有。var_dump($result) 结果为“布尔假”。当我从命令行插入查询时,它可以工作。
功能:
function handlePostForm(){
date_default_timezone_set('UTC');
if($_SERVER["REQUEST_METHOD"] == "POST"){
if(isset($_POST['formSumbit']) && !empty($_POST['newheader']) && !empty($_POST['newpost']))
{
$varHeader = $_POST['newheader'];
$varContent = $_POST['newpost'];
$varDate = date('Y-m-d');
$order ="INSERT INTO posts (header,content,post_date) VALUES ('$varHeader','$varContent','$varDate')";
$result = mysql_query($order);
}
else
echo "error";
}
}
除了调用函数的 html 表单:
<?php include('post_func.php'); ?>
<title>new post</title>
</head>
<body dir="rtl">
<h1>new post</h1>
<form method='post' action="<?php $_SERVER["PHP_SELF"]?>">
header:
<input type="text" name="newheader" maxlength="100" style="width:500px;">
post:
<textarea <input type="text" name="newpost" maxlength="100" style="width:500px; height:500px;"/></textarea>
<input type="submit" name="formSumbit" value="sumbit" />
</form>
<?php
handlePostForm();
?>