kamal213 Posted August 2, 2011 Share Posted August 2, 2011 Hi guys, I was wondering if there is a way or if its possible to check the database if the field has already been updated..just like you would if data has already been inserted into the field. Please let me know if you need more info Thanks Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/ Share on other sites More sharing options...
kickstart Posted August 2, 2011 Share Posted August 2, 2011 Hi Depends on the situation. If you were inserting a record that has some unique key field then you use ON DUPLICATE KEY UPDATE syntax to catch it and instead update the row. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250606 Share on other sites More sharing options...
Muddy_Funster Posted August 2, 2011 Share Posted August 2, 2011 You posted this exact same question in PHP support. Don't duplicate your posts (against the rulles) and if you hadn't wasted time typing the same thing twice you could have used it to post some relevent information regarding the scenrio that you are describing. Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250610 Share on other sites More sharing options...
kamal213 Posted August 2, 2011 Author Share Posted August 2, 2011 Hey men am new to all this so I am not aware of any rules, Am just a normal guy asking you pros for help, If you want to help please do if you dont want to help then dont. Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250620 Share on other sites More sharing options...
Muddy_Funster Posted August 2, 2011 Share Posted August 2, 2011 You've made over 60 posts so your not that new, also you agreed to the Rules when you created your account. I was giving you advice and so in a way trying to help you, but OK, some more direct help for you then: Forum Rules Failure to comply with any of the following rules is breach of contract and as such, administrators and moderators can take appropriate action as they see fit. If there is any contradiction between the Terms of Service and these rules, the Terms of Service shall take precedence. All users must read and agree to the PHP Freaks Terms of Service found above before creating an account. All users must be courteous to others. All users are strongly encourage to abide by the Forum Guidelines. All users acknowledge that PHP Freaks Administration have ultimate control over topics that a user posts. Advertising and Spam are not allowed and is under a zero-tolerance ban/removal from PHP Freaks Forums. Any sticky topic posted at the top of a forum can be considered a rule if the contents merit as such. Signatures may contain textual links to your website(s) as long as it is not overdone/distracting to users. Any adult material (18+) is NOT allowed in the forums. If your posts contain links to such material, remove the links before posting. Any content posted that is hereby deemed Illegal or makes references to illegal content is hereby prohibited, will be deleted and action may be taken against the user who posts such materials. By no means will any staff member change a user's account name or delete a user account. So do not ask. Flaming and or Trolling is prohibited and will result in course of action to be taken by Staff members. All request for code to be written for you should be posted under the freelance section. No exceptions. Duplication of topics is strictly prohibited. Users will not post duplicate topics, if a topic needs moved please use the "Report to Moderator" button and a staff member will move the topic as soon as possible. Users will not act as though they are staff members, and users will not judge other users' behavior. If you believe a user is breaking the rules or Terms of Service, please contact a member of staff using either the "Report to moderator" link found at the bottom of each post, or by sending them a PM (Private Message). Users are allowed to have one account only. Creating multiple accounts per person may result in having all of them banned. Users are not allowed to contact members or staff members with the intention of receiving help with subjects covered in any boards. Users should not "bump" topics that are still on the first page of the forums. If you bump, you must provide additional information. If you resort to bumping, chances are your question needs to be re-thought and re-described (see Eric Raymond's "How To Ask Questions The Smart Way"). Private disputes must be handled privately. Do not use one of the public forums for this. And you still need to provide more information about what it is you are trying to do, to what, and what data is already there if any, for you to get the help that you are looking for. Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250624 Share on other sites More sharing options...
trq Posted August 2, 2011 Share Posted August 2, 2011 Muddy_Funster, you might want to read the rule right under the one you highlighted. Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250631 Share on other sites More sharing options...
kamal213 Posted August 2, 2011 Author Share Posted August 2, 2011 I havent been here long enough to know all the rules you have listed Muddy_Funster..you obviously have that why you do. I did what I did because I wanted the perspective of someone good with PHP and someone good with SQL..i simple copied n paste to save time obviously the mistake - Again I wasnt aware of the rules.. I know now. The code below checks to see if there is a duplicate sales record for a customer when inserting into the table and if there is it redirect to an error page. I want to know if you can do the same for when you are updating a table. // See if that customers sale has already been recorded $sql = mysql_query("SELECT * FROM salesrecord WHERE customer ='$customer' AND value='$value "); $customerMatch = mysql_num_rows($sql); // count the output amount if ($customerMatch > 0) { while($row = mysql_fetch_array($sql)){ $customer = $row["customer"] header("location: sale_error.php?id=$c_id"); exit(); } } Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250633 Share on other sites More sharing options...
trq Posted August 2, 2011 Share Posted August 2, 2011 I havent been here long enough to know all the rules you have listed Muddy_Funster..you obviously have that why you do. I did what I did because I wanted the perspective of someone good with PHP and someone good with SQL..i simple copied n paste to save time obviously the mistake - Again I wasnt away of the rules.. I know now. You read and agreed to the rules when you signed up. The code below checks to see if there is a duplicate sales record for a customer when inserting into the table. I want to know if you can do the same for when you are updating a table. Of course you can, though the code you have posted doesn't make a great deal of sense. Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250634 Share on other sites More sharing options...
kamal213 Posted August 2, 2011 Author Share Posted August 2, 2011 Never mind my code its not really important..I just wanted to know if it was possible. Seen it is possible.. How would you do it. Is it another SELECT sql query? Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250636 Share on other sites More sharing options...
Muddy_Funster Posted August 2, 2011 Share Posted August 2, 2011 @ thorpe :- I was, as was stated previously, simply proffering advice - at no time did I elude to being a member of the forum staff, or atempt to influence an opinion to that nature, I felt that the OP should be aware of the rules. I then so thought to save the OP the trouble of looking these rulles up and included them in thread for their perusal. I do not generaly feel that there is sufficient cause to report an individual for every flaunting of the rules, when normaly an infomative comment is sufficient. If there is something specific that you would like to draw to my attention that has not been covered here in then do please PM me, I was not intending to cause any problems. @kamal213 :- You would run a select on the fields that you want to update, and then compare any result set information that is returned (that which you get back from the database SELECT query) with the variables that you are looking to use in the update. If it is an exact match then you can then decline to run the update. Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250646 Share on other sites More sharing options...
kamal213 Posted August 2, 2011 Author Share Posted August 2, 2011 Muddy_Funster you are a genius problem solved! And agian I wasnt aware of the rules coz I didnt read them properly when I joined..am sure am not the only one tho, its like term and conditions not everyone reads all 2/3pages. I should have read the rules, I broke the rules and apologies to you and every1 in PHP Freaks including the staff. If you look at my POST you'll find I dont usually break rules and am not here to make trouble simply get advise. My problem is solved and again apologies for the confusion i cause u or any1 before thing get outta hand. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250733 Share on other sites More sharing options...
Muddy_Funster Posted August 2, 2011 Share Posted August 2, 2011 No problem, although I'm confident "genius" is a bit strong. I wasn't trying to make you feel bad, just wanted to make you aware was all. No harm no foul. Good luck Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250737 Share on other sites More sharing options...
AyKay47 Posted August 2, 2011 Share Posted August 2, 2011 Muddy_Funster, you might want to read the rule right under the one you highlighted. this made me Quote Link to comment https://forums.phpfreaks.com/topic/243569-duplicate-updates/#findComment-1250741 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.