drewdan Posted March 24, 2014 Share Posted March 24, 2014 Hi All, Currently building a Joomla component. Having an issue with data being duplicated when I click the save button. Instead of the item in the database being updated a new item is being created, has anyone faced this issue before? I am wondering if it might be to do with my database design. I have named the primary key as journal_id, but I see in the tutorial it is set just to id, is this a requirement for Joomla to function properly? Any help with this issue would be gratefully received. Andrew Quote Link to comment https://forums.phpfreaks.com/topic/287234-joomla-component-duplicating-data-on-save/ Share on other sites More sharing options...
QuickOldCar Posted March 24, 2014 Share Posted March 24, 2014 Without knowing anything you are doing..... A link to the tutorial could help. To eliminate any duplicates....but will not help you for updating them. Run this mysql command using your values for tableName and columnName ALTER IGNORE TABLE tableName ADD UNIQUE (columnName); otherwise: Do a query on a specific value that should be unique and check that it does not exist before doing an insert. Can use if/else mysql statements to determine if is new data or update an existing one. This is just an example. //do a query something that has a unique value like an id,url or title $query = mysql_query("SELECT * FROM tableName WHERE title = '" . $escaped_title . "'"); //this will determine if it exists by seeing how many rows exist $check = mysql_num_rows($query); if ($check > 0) { //if exists update by using the id $row = mysql_fetch_array($query); $the_ID = $row['ID']; mysql_query("UPDATE tableName SET title='$escaped_title', description='$escaped_description', url='$escaped_url' WHERE ID='$the_ID'"); } else { //if does not exist insert a new and uses autoincrement id's mysql_query("INSERT INTO tableName (title,description,url) VALUES ('$escaped_title','$escaped_description','$escaped_url')"); } Quote Link to comment https://forums.phpfreaks.com/topic/287234-joomla-component-duplicating-data-on-save/#findComment-1473762 Share on other sites More sharing options...
drewdan Posted March 25, 2014 Author Share Posted March 25, 2014 Hi, Thanks for the information, very helpful. The tutorial I am following is here: http://docs.joomla.org/J3.2:Developing_a_MVC_Component/Adding_backend_actions For some reason the data is duplicated on save instead of being updated. Very annoying! Quote Link to comment https://forums.phpfreaks.com/topic/287234-joomla-component-duplicating-data-on-save/#findComment-1473882 Share on other sites More sharing options...
mac_gyver Posted March 26, 2014 Share Posted March 26, 2014 no one can tell you, just based on the symptom, what exactly your code is doing that could cause that symptom. it will take seeing your code in order to help you at all or to even narrow down the possibilities to just one or two likely things to investigate further. Quote Link to comment https://forums.phpfreaks.com/topic/287234-joomla-component-duplicating-data-on-save/#findComment-1473918 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.