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 Link to comment https://forums.phpfreaks.com/topic/94857-query-help/ 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 Link to comment https://forums.phpfreaks.com/topic/94857-query-help/#findComment-485871 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. Link to comment https://forums.phpfreaks.com/topic/94857-query-help/#findComment-485873 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). Link to comment https://forums.phpfreaks.com/topic/94857-query-help/#findComment-485875 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 ??? Link to comment https://forums.phpfreaks.com/topic/94857-query-help/#findComment-485877 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. Link to comment https://forums.phpfreaks.com/topic/94857-query-help/#findComment-485893 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"; Link to comment https://forums.phpfreaks.com/topic/94857-query-help/#findComment-485899 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 Link to comment https://forums.phpfreaks.com/topic/94857-query-help/#findComment-485908 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.