Insert value on update or insert
Posted: 2017-08-08 09:48
Hello,
I am a php programmer but I have a little bit of trouble to understand how to simply insert data in a table.
Here is what I would like to achieve:
1)When the user update, or insert data in a form, I would like to take 1 field from that form and copy it in another row.
2)This is my table structure:
Table: news
field1: google_title
field2: seo_friendly_url
At the moment, in the hook folder I have created a new function:
Then called this function here:
and here:
I would have expected this to work but it is not, any idea why please?
I am simply trying to copy over the data from the field google_title to seo_friendly_url, when I get this going, I will add a new function that rewrite the url in a friendly way but the most important for me is to get the first part going.
Thank you!
I am a php programmer but I have a little bit of trouble to understand how to simply insert data in a table.
Here is what I would like to achieve:
1)When the user update, or insert data in a form, I would like to take 1 field from that form and copy it in another row.
2)This is my table structure:
Table: news
field1: google_title
field2: seo_friendly_url
At the moment, in the hook folder I have created a new function:
Code: Select all
function update_seo_friendly_url($data){
sql("UPDATE news
SET seo_friendly_url = '{$data['google_title']}'
WHERE id={$data['$id']}", $eo);
}
Code: Select all
function news_after_update($data, $memberInfo, &$args){
update_seo_friendly_url($data);
return TRUE;
}
and here:
Code: Select all
function news_after_insert($data, $memberInfo, &$args){
update_seo_friendly_url($data);
return TRUE;
}
I would have expected this to work but it is not, any idea why please?
I am simply trying to copy over the data from the field google_title to seo_friendly_url, when I get this going, I will add a new function that rewrite the url in a friendly way but the most important for me is to get the first part going.
Thank you!