有人知道我在下面的代码做错了什么吗?我得到它来抓取变量并很好地显示主题、消息和日期,但我想做的是让它从变量中添加主题(来自文本区域的新自定义消息)和变量中的日期数据库。
<?php
require("db.php");
$query_params = array(
':id' => $_GET['id'],
':username' => $_SESSION['user']['username']
);
$query = "SELECT id, subject, message, date FROM tickets
WHERE username = :username And id= :id";
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
$result = $stmt->setFetchMode(PDO::FETCH_NUM);
while ($row = $stmt->fetch($result)) {
echo $row['subject'];
echo $row['message'];
echo $row['date'];
PROBLEMS WITH THE CODE BELOW>>>>
if(!empty($_POST))
{
if(empty($_POST['message']))
{
$error="Please enter a Message.";
}
else
{
$query = "
INSERT INTO supporttickets (
username,
subject,
message,
date
) VALUES (
:username,
:subject,
:message,
date
)
";
$query_params = array(
':username' => $_SESSION['user']['username'],
':subject' => $_POST['subject'],
':date' => $_POST['date'],
':message' => $_POST['message']
);
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
}
}
}
?>
<form action="" method="post" name="form">
<textarea name="message" cols="71" rows="9" id="message"></textarea>
<input type="submit" value="Submit" />
</form>