PriteshP23 Posted August 9, 2013 Share Posted August 9, 2013 Update is not working.. UPDATE Customers SET ContactName='Alfred Schmidt', City='Hamburg' WHERE CustomerFirstName='Alfreds' AND CustomerLastName='Futterkiste' Thanks in advanced. Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/ Share on other sites More sharing options...
Muddy_Funster Posted August 9, 2013 Share Posted August 9, 2013 what happens when you run the query? do you get any errors? Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444187 Share on other sites More sharing options...
PriteshP23 Posted August 12, 2013 Author Share Posted August 12, 2013 Not errors. But it is not working. Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444486 Share on other sites More sharing options...
PriteshP23 Posted August 12, 2013 Author Share Posted August 12, 2013 After running above query: " Number of records affected: 0 (Processing 1.5935 sec.) " Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444487 Share on other sites More sharing options...
mac_gyver Posted August 12, 2013 Share Posted August 12, 2013 that would mean that your WHERE clause if false. have you looked in your database table to see if there's a row with those values in it? Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444514 Share on other sites More sharing options...
PriteshP23 Posted August 12, 2013 Author Share Posted August 12, 2013 YES, i did. Thats why i want to update the table. Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444516 Share on other sites More sharing options...
Psycho Posted August 12, 2013 Share Posted August 12, 2013 What does this query return? SELECT COUNT(*) FROM Customers WHERE CustomerFirstName='Alfreds' AND CustomerLastName='Futterkiste' Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444518 Share on other sites More sharing options...
PriteshP23 Posted August 12, 2013 Author Share Posted August 12, 2013 (edited) COUNT(*) 4 Edited August 12, 2013 by PriteshP23 Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444525 Share on other sites More sharing options...
PriteshP23 Posted August 12, 2013 Author Share Posted August 12, 2013 There are multi-rows i need to update for sure. I have already cross check all values. Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444526 Share on other sites More sharing options...
mac_gyver Posted August 12, 2013 Share Posted August 12, 2013 i'll add an edit to my reply #5 - ... OR it means that the columns already have the values you are trying to update them to. Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444528 Share on other sites More sharing options...
PriteshP23 Posted August 12, 2013 Author Share Posted August 12, 2013 Based on CustomerFirstName='Alfreds' AND CustomerLastName='Futterkiste' VALUES only i have to update other columns like City. But by default city is NULL. I hope i am clear. Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444529 Share on other sites More sharing options...
mikosiko Posted August 12, 2013 Share Posted August 12, 2013 post your full table definition and the complete results of this query: SELECT * (or at least "CustomerFirstName, CustomerLastName, ContactName and City") FROM Customers WHERE CustomerFirstName='Alfreds' AND CustomerLastName='Futterkiste' Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444559 Share on other sites More sharing options...
jazzman1 Posted August 12, 2013 Share Posted August 12, 2013 (edited) COUNT(*) 4 Hm.....it's very weird! What SQL editor are you using to achive that? Anyways, it sounds like ( not sure) the SQL_SAFE_UPDATES is set up to ON. So, before to send an update command to the sql server, run that: SET SQL_SAFE_UPDATES=0; Edited August 12, 2013 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444584 Share on other sites More sharing options...
PriteshP23 Posted August 13, 2013 Author Share Posted August 13, 2013 post your full table definition and the complete results of this query: SELECT * (or at least "CustomerFirstName, CustomerLastName, ContactName and City") FROM Customers WHERE CustomerFirstName='Alfreds' AND CustomerLastName='Futterkiste' ID CustomerFirstName CustomerLastName ContactName City Company 1 Alfreds Futterkiste NULL NULL Dell 3 Alfreds Futterkiste NULL NULL Dell 4 Alfreds Futterkiste NULL NULL Dell 5 Alfreds Futterkiste NULL NULL Dell Hm.....it's very weird! What SQL editor are you using to achive that? I'm using database: MySQL client version: 5.0.45 I tried SET SQL_SAFE_UPDATES=0; Can you tell me more about SAFE UPDATES ?? Still it's not working.. Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444711 Share on other sites More sharing options...
mikosiko Posted August 13, 2013 Share Posted August 13, 2013 You didn't post the full definition of your table...the one that start with CREATE TABLE.... etc..etc Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444717 Share on other sites More sharing options...
PriteshP23 Posted August 13, 2013 Author Share Posted August 13, 2013 You didn't post the full definition of your table...the one that start with CREATE TABLE.... etc..etc Here it is: CREATE TABLE IF NOT EXISTS `Customers` ( `ID` int(10) NOT NULL auto_increment, `CustomerFirstName` varchar(30) default NULL, `CustomerLastName` varchar(30) default NULL, `ContactName` varchar(30) default NULL, `City` varchar(30) default NULL, `Company` varchar(20) default NULL, PRIMARY KEY (`ID`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Cutomers Data ' AUTO_INCREMENT=7 ; Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444721 Share on other sites More sharing options...
jazzman1 Posted August 13, 2013 Share Posted August 13, 2013 I tried SET SQL_SAFE_UPDATES=0; Can you tell me more about SAFE UPDATES ?? It's a useful startup option for beginners in sql, which allows you to update(delete) rows only by specifying the key values that identify them, like in your example! So, I don't see nothing wrong in your database structure. I am out. Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444745 Share on other sites More sharing options...
Solution PriteshP23 Posted August 13, 2013 Author Solution Share Posted August 13, 2013 In database, I wrote: UPDATE Customers SET ContactName='Alfred Schmidt' AND City='Hamburg' WHERE CustomerFirstName='Alfreds' AND CustomerLastName='Futterkiste' It must be: UPDATE Customers SET ContactName='Alfred Schmidt' , City='Hamburg' WHERE CustomerFirstName='Alfreds' AND CustomerLastName='Futterkiste' Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444756 Share on other sites More sharing options...
mac_gyver Posted August 13, 2013 Share Posted August 13, 2013 LOL, the query you posted at the start of this thread is the correct syntax and we only see and can only help you based on the information you provided in your posts. in the future, copy paste the actual query/code you need help with to avoid wasting everyone's time. Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444759 Share on other sites More sharing options...
mikosiko Posted August 13, 2013 Share Posted August 13, 2013 how that old say goes?..... "if everything looks right, then for sure you will find the issue between the keyboard and the chair" Quote Link to comment https://forums.phpfreaks.com/topic/280992-update-multicolumns-in-table/#findComment-1444777 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.