Ok i updated my code to this:
<?php
if ( $form->data['Alert'] ) {
$new_alerts = $form->data['Alert'];
JFactory::getApplication()->enqueueMessage( $new_alerts );
$user =& JFactory::getUser();
$userid = $user->id ;
JFactory::getApplication()->enqueueMessage( $userid );
$db =& JFactory::getDBO();
$query = "
SELECT Alert
FROM #__userstest
WHERE id = '$userid' ;
";
$db->setQuery($query);
$alerts = $db->loadResult();
JFactory::getApplication()->enqueueMessage( $alerts );
$alerts = explode(',', $alerts);
print_r($alerts);
$alerts = array_merge((array)$alerts, (array)$new_alerts);
print_r($alerts);
$form->data['Alert'] = implode(',', $alerts);
}
?>
What i get as output is:
Aerospace,Gaming,Market //The 3 enque messages
65
Otinane
Array ( [0] => Otinane ) // This is the print_r($alerts) message from explode
Array ( [0] => Otinane [1] => Aerospace,Gaming,Market ) // This is the print_r($alerts) message from the merge of arrays
Array // This is the new data stored in userstest table
(
[Alert] => Otinane,Aerospace,Gaming,Market
[input_submit_1] => Submit
[12c174c52941cbdb4dba5f1af2badd3c] => 1
[option] => com_chronoforms
[chronoform] => Alert
[event] => submit
[Itemid] =>
[Alert[]] => Array
(
[cf_uid] => 25d425dfe1eeadcafdb002a8948c67ff
[cf_created] => 2011-09-23 11:06:04
[cf_ipaddress] => 79.130.109.203
[cf_user_id] => 65
[Alert] => Otinane,Aerospace,Gaming,Market
[input_submit_1] => Submit
[12c174c52941cbdb4dba5f1af2badd3c] => 1
[option] => com_chronoforms
[chronoform] => Alert
[event] => submit
[Itemid] =>
[id] => 6833
)
[alert[]_id] => 6833
)
As u can see above now the code works almost as it should,joining the logged in users Alert field with the data that we provide in the form.One big problem though...
The code still generates a new entry in userstest table under new id,whereas what i want is update the already existing entry of the logged in user under the field Alert.
Any ideas?
P.S. Just to provide some future help,the problem with the errors of the previous post i solved it by using array(),array() in each argument at array_merge arguements ((array)$alerts,(array)$new_alerts) due to PHP 5