更新新记录时恢复以前更新的记录 MySQL PHP
祝大家美好的一天。我正在尝试为我的系统制作一个任务跟踪模块。逻辑是,每当我将任务分配给用户时,系统都会将该任务更新为“IsTaken”,这意味着特定用户负责该任务。更新后,它会在“user_task”表中创建一个条目,该条目基本上将任务和用户表联系在一起。每当我将任务分配给某人时都很好。但是,当我再次执行此操作时,前一个任务记录的 IsTaken 字段将恢复为 0。我尝试重新分配它,但前一个记录又恢复为 0。这很奇怪。我正在使用 XAMPP、MySQL 和 PHP。我希望我不是唯一经历过这种事的人。任何帮助将不胜感激。
这是我的表格:
CREATE TABLE IF NOT EXISTS `task` (
`Task_No` int(11) NOT NULL AUTO_INCREMENT,
`Task_Name` varchar(100) NOT NULL,
`Task_Desc` varchar(450) DEFAULT NULL,
`Task_DateCreated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Task_IsTaken` tinyint(1) NOT NULL,
PRIMARY KEY (`Task_No`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `user_task` (
`UT_No` int(11) NOT NULL AUTO_INCREMENT,
`User_Email` varchar(100) NOT NULL,
`Task_No` int(11) NOT NULL,
`Task_Duration` varchar(20) NOT NULL,
`Task_DateTaken` date DEFAULT NULL,
`Task_DateFinished` timestamp NULL DEFAULT NULL,
`Task_IsIssue` tinyint(1) NOT NULL,
PRIMARY KEY (`UT_No`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
这是我的脚本(来自表单):
//Process - Insert Task
if(isset($_POST['btnCreateTask']))
{
if($_POST['taskName']!=NULL)
{
$taskName = mysql_real_escape_string ($_POST['taskName']);
$taskDesc = mysql_real_escape_string ($_POST['taskDesc']);
$insertTask = "INSERT INTO task(Task_Name, Task_Desc, Task_IsTaken) VALUES('$taskName', '$taskDesc', 0)";
$sqlResult1 = mysql_query($insertTask);}
else
{
echo "No task name given";
$errorCode = 1;
}
}
if(isset($_POST['btnAssignTask']))
{
if($_POST['assignTaskName']!=NULL)
{
$assigntaskName = mysql_real_escape_string($_POST['assignTaskName']);
$assigntaskNo = mysql_real_escape_string($_POST['assignTaskNo']);
$assigntaskOwner = mysql_real_escape_string($_POST['assignTaskOwner']);
$assigntaskDuration = mysql_real_escape_string($_POST['assignTaskDuration']);
$updateUpcomingTask = "UPDATE task SET Task_IsTaken = '1' AND Task_No = '$assigntaskNo'";
$createUserTask = "INSERT INTO user_task (User_Email, Task_No, Task_Duration, Task_DateTaken, Task_DateFinished)
VALUES ('$assigntaskOwner', '$assigntaskNo', '$assigntaskDuration', '$now', NULL)";
$sqlResult2 = mysql_query($updateUpcomingTask);
$sqlResult3 = mysql_query($createUserTask);
}
else
{
echo "No task selected";
$errorCode = 2;
}
}
Good day to all. I'm trying to make a task tracking module for my system. The logic is, whenever I assign a task to a user, the system updates the task to "IsTaken" meaning the particular user is responsible for that task. Upon updating, it creates an entry into "user_task" table which basically ties together the task and the user table. Whenever I assign a task to somebody it's fine. But when I do it again, the previous task record's IsTaken field reverts back to 0. I try to re-assign it, but again, the previous record reverts. It's quite weird. I'm using XAMPP, MySQL and PHP. I'm hoping I'm not the only one experiencing this. Any help would be much appreciated.
Here are my tables:
CREATE TABLE IF NOT EXISTS `task` (
`Task_No` int(11) NOT NULL AUTO_INCREMENT,
`Task_Name` varchar(100) NOT NULL,
`Task_Desc` varchar(450) DEFAULT NULL,
`Task_DateCreated` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`Task_IsTaken` tinyint(1) NOT NULL,
PRIMARY KEY (`Task_No`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
CREATE TABLE IF NOT EXISTS `user_task` (
`UT_No` int(11) NOT NULL AUTO_INCREMENT,
`User_Email` varchar(100) NOT NULL,
`Task_No` int(11) NOT NULL,
`Task_Duration` varchar(20) NOT NULL,
`Task_DateTaken` date DEFAULT NULL,
`Task_DateFinished` timestamp NULL DEFAULT NULL,
`Task_IsIssue` tinyint(1) NOT NULL,
PRIMARY KEY (`UT_No`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
And here are my scripts (from the form):
//Process - Insert Task
if(isset($_POST['btnCreateTask']))
{
if($_POST['taskName']!=NULL)
{
$taskName = mysql_real_escape_string ($_POST['taskName']);
$taskDesc = mysql_real_escape_string ($_POST['taskDesc']);
$insertTask = "INSERT INTO task(Task_Name, Task_Desc, Task_IsTaken) VALUES('$taskName', '$taskDesc', 0)";
$sqlResult1 = mysql_query($insertTask);}
else
{
echo "No task name given";
$errorCode = 1;
}
}
if(isset($_POST['btnAssignTask']))
{
if($_POST['assignTaskName']!=NULL)
{
$assigntaskName = mysql_real_escape_string($_POST['assignTaskName']);
$assigntaskNo = mysql_real_escape_string($_POST['assignTaskNo']);
$assigntaskOwner = mysql_real_escape_string($_POST['assignTaskOwner']);
$assigntaskDuration = mysql_real_escape_string($_POST['assignTaskDuration']);
$updateUpcomingTask = "UPDATE task SET Task_IsTaken = '1' AND Task_No = '$assigntaskNo'";
$createUserTask = "INSERT INTO user_task (User_Email, Task_No, Task_Duration, Task_DateTaken, Task_DateFinished)
VALUES ('$assigntaskOwner', '$assigntaskNo', '$assigntaskDuration', '$now', NULL)";
$sqlResult2 = mysql_query($updateUpcomingTask);
$sqlResult3 = mysql_query($createUserTask);
}
else
{
echo "No task selected";
$errorCode = 2;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码应更改为:
Your code should be changed to: