johntp Posted August 27, 2008 Share Posted August 27, 2008 Hey guys, I'm not sure how to set this up. I want to update only one column in a row in php. when i try <? $query = "REPLACE INTO visitors (TimeOut) VALUES ( '$TimeOut') WHERE EmployeeID = '$Employee'; ?> but it needs a value for all of my columns in that row to update. Link to comment https://forums.phpfreaks.com/topic/121587-solved-update-column-only-in-an-sql-statement/ Share on other sites More sharing options...
wildteen88 Posted August 27, 2008 Share Posted August 27, 2008 If you only want to update a single column within a row you use the UPDATE query, eg $query = "UPDATE visitors SET TimeOut='$TimeOut' WHERE EmployeeID = '$Employee'"; Link to comment https://forums.phpfreaks.com/topic/121587-solved-update-column-only-in-an-sql-statement/#findComment-627099 Share on other sites More sharing options...
discomatt Posted August 27, 2008 Share Posted August 27, 2008 REPLACE INTO works well, but you have to read the syntax. There shouldn't be a WHERE clause - it takes a primary or unique column and if a duplicate exists, it updates rather than inserts. <? $query = "REPLACE INTO visitors (EmployeeID, TimeOut) VALUES ('$Employee', '$TimeOut')"; ?> Link to comment https://forums.phpfreaks.com/topic/121587-solved-update-column-only-in-an-sql-statement/#findComment-627102 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.