I am trying to insert data that the user submits from a drop down box and a text box, however this data is not being inserted into my Database Table.
The Drop Down and text box code:
echo 'Tasks: <select name="selected_task">
<option value=""> ---Select ---- </option><br><br><br><br>';
/*
Query code to retrieve options goes here and assign it to a variable named '$tasks'
*/
while ($row_list = mysql_fetch_assoc($tasks))
{
echo '<option>' . $row_list['taskname'];
if ($row_list['taskname']==$select) { echo $row_list['taskname']; }
echo '</option>';
}
echo '</select>';
echo '<div id="task_hours">
<form name="hours" method="post" action="login.php?action=hours">
Hours: <input type="text" name="hours" value="" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
</div>';
Database insertion code :
$posted_client = $_POST['selected_client'];
$posted_task = $_POST['selected_task'];
$conn_task = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$inserted_time = "INSERT INTO tasks (taskhours) VALUES :posted_hours WHERE taskname = :posted_task ";
$sp = $conn_task ->prepare ( $inserted_time);
$sp->bindValue(":posted_hours", $posted_hours, PDO::PARAM_STR); // Make sure you use PDO::PARAM_STR for decimals
$sp->bindValue(":posted_task", $posted_task, PDO::PARAM_STR);
$sp->execute();
$conn_task = null;
echo "Your total time has been entered!<br>";
echo "Your Total Hours: " . $posted_hours;
When the form appears and I click on the 'submit' button after entering data, no error message appears but the number of hours for the table field 'taskhours' is not being updated.