controller methods of a block
Permalink
Hello everyone! I am new in concrete5 and recently I have tried to make my own block. Everytime I edit my block and click save after I have logged out then logged in it will say error 1062 a conflict in primary in database etc.. but when I delete that particular block and add another the conflict will go away.
Steps:
1. Logout and Login to my local
2. Click edit then edit my block
3. Error pops out
(Currently logged in)
1. Delete current block.
2. Add the block then save and publish my edits etc..
3. Click edit to be in edit mode then edit my block
4. Click save (given there's a same data entry in my database).
5. Database gets updated with no errors.
But when I sign out then sign in and do the following steps the error will occur.
This is my error
An unexpected error occurred. mysql error: [1062: Duplicate entry '59' for key 'PRIMARY'] in EXECUTE("INSERT INTO...
Any help? Thanks in advance! :D
Steps:
1. Logout and Login to my local
2. Click edit then edit my block
3. Error pops out
(Currently logged in)
1. Delete current block.
2. Add the block then save and publish my edits etc..
3. Click edit to be in edit mode then edit my block
4. Click save (given there's a same data entry in my database).
5. Database gets updated with no errors.
But when I sign out then sign in and do the following steps the error will occur.
This is my error
An unexpected error occurred. mysql error: [1062: Duplicate entry '59' for key 'PRIMARY'] in EXECUTE("INSERT INTO...
Any help? Thanks in advance! :D
its difficult to say anything without looking into the controller of your block.
$db = Loader::db(); $linkarr = array(); $imagearr = array(); $typearr = array(); $linkarr = $data['linkurl']; $imagearr = $data['imageurl']; $typearr = $data['linktype']; $thisID = $this->bID; $q = "SELECT count(*) as total from btDCDgwebanner where bID = ".intval($this->bID); $total = $db->getOne($q); //echo 'This is total: ' . $total; if( intval($total) > 0 ){ //If not new $q = "DELETE FROM btDCDgwebanner WHERE bID = '" . $thisID . "'"; $db->query($q);
Viewing 15 lines of 32 lines. View entire code block.
This is my code.. I don't know if I am doing something wrong.
This is my save function.
There is no suspicious code that I can see. Maybe this will be helpful: http://www.concrete5.org/documentation/how-tos/developers/fix-block...
Rony
Rony
Your error comes from an sql Insert statement and refers to trying to have to rows with a primary key having the same value.
In the code you posted you have only one Insert statement so that's where you have to look.
My guess is that the field bID is a primary key and you are trying to save more than one line with the same bID which will happen if your $linkArr contains more than one value.
Either make your bID a non primary field IF AND ONLY IF it is not the block's main table.
If it is the block's main table you might want to consider saving your data in a secondary table if indeed there should be more than one line per bID.
OR you should make sure your $linkArr has only one value.
In the code you posted you have only one Insert statement so that's where you have to look.
My guess is that the field bID is a primary key and you are trying to save more than one line with the same bID which will happen if your $linkArr contains more than one value.
Either make your bID a non primary field IF AND ONLY IF it is not the block's main table.
If it is the block's main table you might want to consider saving your data in a secondary table if indeed there should be more than one line per bID.
OR you should make sure your $linkArr has only one value.