Reputation: 17
I am implementing employee attendance system. Can you please tell me what is wrong in the following query:
INSERT INTO tbtimedetail (outTime) VALUES (NOW()) WHERE empID= '$empid_var' and outTime='NULL';
Structure of tbtimedetail is:
CREATE TABLE tbTimeDetail(
timeID Int PRIMARY KEY AUTO_INCREMENT,
empID Int(5),
dateDetail Date NOT NULL,
inTime Time NOT NULL,
outTime Time NOT NULL,
FOREIGN KEY (empID) REFERENCES tbempdetail (empID)
);
Upvotes: 1
Views: 69
Reputation: 2149
As suggested by Matt, you should use IS NULL to check if it is null or not?
Also Try CURRENT_TIME() method instead of NOW(). Refer the below url for more Mysql time related methods and operations: http://www.roseindia.net/sql/sqldate/mysql-time-function.shtml
Upvotes: 0
Reputation: 79969
You should use UPDATE
instead of INSERT
like this:
UPDATE tbtimedetails t
SET t.outTime = NOW()
WHERE t.empID = '$empid_var' AND t.outTime IS NULL
Upvotes: 0
Reputation: 206831
insert
only adds rows to a database. A where filter doesn't make sense in that case.
It looks like you're trying to update existing rows:
update tbtimedetail
set outTime = NOW()
WHERE empID= '$empid_var' and outTime is NULL;
Upvotes: 1