Writing back to DB

tullski 25 Aug, 2008
Hi,

yes me again -i have a strange problem.
I like to write back to a table, but i can`t see all the fields get updated. only numbers without whitespace seem to work.
I put the php in On Submit code - after sending email:, cause in the autogenerated code it`s get stripped out.

So this one is working
<?php
$myuser= JRequest::getVar( 'theuser_id', 0 );
$myplz = JRequest::getVar( 'cb_plz', 0 );

$database = &JFactory::getDBO();
$database->setQuery("UPDATE #__comprofiler SET cb_plz=$myplz WHERE user_id=$myuser;");
$database->query();
?>



This not - why
<?php
$myuser= JRequest::getVar( 'theuser_id', 0 );
$myland = JRequest::getVar( 'cb_land', 'none', 'POST', 'STRING' );

$database = &JFactory::getDBO();
$database->setQuery("UPDATE #__comprofiler SET cb_land=$myland WHERE user_id=$myuser;");
$database->query();
?>



i also tried
$myland = addslashes(JRequest::getVar( 'cb_land', 'none', 'POST', 'STRING' ));
$myland = addslashes(trim(JRequest::getVar( 'cb_land', 'none', 'POST', 'STRING' )));

no luck...pls help.
All latest J1.5.6, CB 1.2, CF V3 beta2 and mambot 0.6
thx
M
GreyHead 25 Aug, 2008
Hi tullski,

Try putting single quotes round the variable names in the SQL:
$sql = "
    UPDATE #__comprofiler 
        SET cb_plz = '$myplz' 
        WHERE user_id = '$myuser'";
$database->setQuery($sql);

Bob
Max_admin 25 Aug, 2008
Hi tullski,

I believe Bob's fix will do it, another way is that you use the built in features of V3 to achieve what you need easily and quickly, if your form is connected to jos_comprofiler and DB connection in ON and your form has a field names cb_plz and jos__comprofiler has a column called cb_plz and the column data type is ok to accept the posted data, and your form also has a field with the same name as the table PRIMARY key loaded with some value then Chronoforms will automatically update your table row!

e.g: this is your form code :

<input type="hidden" name="id" value="65">
<input type="hidden" name="cb_plz" value="65">


when you submit the form, the row with id=65 will get updated, but be carefull because if no other columns are posted then all other columns will be updated to " " null!
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
This topic is locked and no more replies can be posted.