scarface83 Posted April 28, 2007 Share Posted April 28, 2007 how do you insert into a row that already exsists ? i have this table im trying to insert into and empty field on an already exsisting row datestamp abs_value ID notes viewable TeamRef 2007-04-28 0 vtc1kb 1 14 2007-04-28 0 vtc2a7 1 14 2007-01-01 1 vtc1kb test 0 0 and want to do the following query $query = "INSERT INTO absence_mgt SET abs_value='1', notes='testing' WHERE datestamp='2007-04-28', ID='vtc2av' "; // inserts the selection from the form into the db $result = mysql_query($query) or die (mysql_error()); // runs the above query im getting the following error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE datestamp='2007/04/28', ID='vtc2av' at line 1 do i need to use and update statemnet and if so how do i do it ? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/49066-solved-my-sql-error-with-insert/ Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 INSERT = NEW UPDATE = erm.. well UPDATE and existing one and the WHERE needs to have operators!! what are you trying to do ? WHERE datestamp='2007-04-28', ID='vtc2av' this datestamp='2007-04-28' AND ID='vtc2av' or datestamp='2007-04-28' OR ID='vtc2av' what!!! Quote Link to comment https://forums.phpfreaks.com/topic/49066-solved-my-sql-error-with-insert/#findComment-240399 Share on other sites More sharing options...
paul2463 Posted April 28, 2007 Share Posted April 28, 2007 try this one <?php $query = "INSERT INTO absence_mgt (abs_value, notes) VALUES ('1', 'testing') WHERE datestamp='2007-04-28', ID='vtc2av' "; $result = mysql_query($query) or die (mysql_error()); // runs the above query ?> an insert query should be "INSERT INTO tbl_name (col1,col2) VALUES(15,col1*2);" edit: madTechie I should have read your post as well UPDATE or INSERT??? Quote Link to comment https://forums.phpfreaks.com/topic/49066-solved-my-sql-error-with-insert/#findComment-240401 Share on other sites More sharing options...
scarface83 Posted April 28, 2007 Author Share Posted April 28, 2007 sorry guys im trying to update then will this work $query1 = "UPDATE absence_mgt SET abs_value='1', notes='testing', viewable='0' WHERE datestamp='2007-04-28' AND ID='vtc2av' "; // inserts the selection from the form into the db thanks Quote Link to comment https://forums.phpfreaks.com/topic/49066-solved-my-sql-error-with-insert/#findComment-240403 Share on other sites More sharing options...
MadTechie Posted April 28, 2007 Share Posted April 28, 2007 looks ok, have you tried it ? Quote Link to comment https://forums.phpfreaks.com/topic/49066-solved-my-sql-error-with-insert/#findComment-240405 Share on other sites More sharing options...
scarface83 Posted April 28, 2007 Author Share Posted April 28, 2007 looks fine , thanks i cant believe i forgot the operator ! , also thanks for your help with that while loop the other day i got it sorted in the end Cheers Quote Link to comment https://forums.phpfreaks.com/topic/49066-solved-my-sql-error-with-insert/#findComment-240409 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.