我正在尝试更新数据库中“已完成”的值,它是一个复选框,因此我想根据数据库中的更改将值更新为 1 或 0,我知道这不是最干净的方法,但是一旦我让它工作,我会清理它!
瑞安
<?php
include 'core/init.php';
if(isset($_POST['Submit']))
{
$task_name = $_POST['task_name'];
$completed = $_POST['completed'];
mysql_query("UPDATE `tasks` SET `completed` = '$completed' WHERE `task_name` = $task_name");
}
$deets = $_POST['deets'];
$deets = preg_replace('#[^0-9/]#i', '', $deets);
$tasks = '';
$query = mysql_query('SELECT task_name, task_description, completed FROM tasks WHERE "'.$deets.'" BETWEEN `start_date` AND `end_date` ');
$num_rows = mysql_num_rows($query);
if($num_rows > 0) {
$tasks .= '<div id="tasksControl"><button onMouseDown="overlay()">Close</button> <b> ' . $deets . '</b> <br /><br /></div>';
while ($row = mysql_fetch_array($query)){
$task_name = $row['task_name'] ;
$task_description = $row['task_description'];
$task_completed = $row['completed'];
$tasks .= '<div id="tasksBody">
<form method="post">Completed? <input name="completed" type="checkbox" '.
($task_completed == 1?'checked="checked"':'').
' /><input type="submit" name="submit" value="Update"><br /><br />
<b>'.$task_name.'</b><br /><br />'.$task_description.'<hr><br />
<input type="hidden" value="$task_name" name="TaskName" /></form></div>';
}
}
echo $tasks;
?>