Jump to content

Joomla component duplicating data on save


drewdan

Recommended Posts

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

 

Link to comment
Share on other sites

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')");
                    }
 
 
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.