aussiefly Posted March 7, 2008 Share Posted March 7, 2008 Hey everyone! I've got a query that im running to stick multiple values into a table ina mysql database. $schedule_insert ="INSERT INTO `days` (monday, tuesday, wednesday, thursday, friday, saturday, sunday) VALUES ('$monday','$tuesday','$wednesday','$thursday','$friday','$saturday','$sunday') WHERE userid = $_SESSION[id]"; $schedule_update = mysql_query($schedule_insert); Now is that the best way to do it and will it work fine??? I've been using the query without the `WHERE` conditional and it works...im just wondering if ive got the WHERE conditional in the right spot. Any ideas Quote Link to comment Share on other sites More sharing options...
Naez Posted March 7, 2008 Share Posted March 7, 2008 You should use UPDATE instead of INSERT in this case, I think Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted March 7, 2008 Share Posted March 7, 2008 Use the where condition when you have to delete or update some entry according to some condition,else the condition is not checked and the data will be updated or deleted without checking the condition attached after the where clause. Quote Link to comment Share on other sites More sharing options...
Naez Posted March 7, 2008 Share Posted March 7, 2008 INSERT is used to create a row in the database, thus I don't think it can be matched with INSERT. You need to use UPDATE as I stated, because the row has already been made (because there is a value for the `userid` already in it). Quote Link to comment Share on other sites More sharing options...
aussiefly Posted March 7, 2008 Author Share Posted March 7, 2008 yup you guys are totally correct...dont know whay i was trying to insert those details rather than update Anyway, even with update it throws an sql syntax error...this seems to happen when im trying to insert multiple values in my query...anyone know where im going wrong ??? Quote Link to comment Share on other sites More sharing options...
rameshfaj Posted March 7, 2008 Share Posted March 7, 2008 You too can update multiple values in a single query,check the syntax or else send the complete query that u are using in your code. Quote Link to comment Share on other sites More sharing options...
Naez Posted March 7, 2008 Share Posted March 7, 2008 yup you guys are totally correct...dont know whay i was trying to insert those details rather than update Anyway, even with update it throws an sql syntax error...this seems to happen when im trying to insert multiple values in my query...anyone know where im going wrong ??? Try this $schedule_update ="UPDATE `days` SET monday = '" . $monday . "', tuesday = '" . $tuesday . "', wednesday = '" . $wednesday . "', thursday = '" . $thursday. "', friday = '" . $friday . "', saturday = '" . $saturday. "', sunday = '" . $sunday . "' WHERE userid = '" . $_SESSION[id] . "' LIMIT 1"; Quote Link to comment Share on other sites More sharing options...
aussiefly Posted March 7, 2008 Author Share Posted March 7, 2008 thanks mate that worked brilliantly....cant beleive i forgot the set cheers Quote Link to comment 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.