1

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)
);
Mat
  • 202,337
  • 40
  • 393
  • 406
Aps
  • 17
  • 7

3 Answers3

1

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;
Mat
  • 202,337
  • 40
  • 393
  • 406
0

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   
Mahmoud Gamal
  • 78,257
  • 17
  • 139
  • 164
0

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

Shahul3D
  • 2,129
  • 1
  • 15
  • 16