Tuesday, 6 August 2013

trying to insert variable on submit with new message

trying to insert variable on submit with new message

anyone have any idea what im doing wrong with my code below? i got it to
grab the variable and show the subject, message and date fine, but what
i'm trying to do is get it to add the subject from the variable (a new
custom message from a textarea) and date from the variable to the
database.
<?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>

No comments:

Post a Comment