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. Quote 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'"; Quote 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')"; ?> Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.