Forums

mysql database UPDATE

AndreaZ 05 Dec, 2009
I want to UPDATE the mysql database field from a chronoforms form.

I have puted in the form code the following, to automatically update che DataRisposta field with the today date:


<p><?php $data = date("Y/m/d"); 
$db =& JFactory::getDBO();
$query = "
UPDATE '#__chronoforms_Messaggi_Backend'
SET 'DataRisposta' = $data
WHERE 'cf_id' = $selezione
";
echo $query;
$db->setQuery($query);
$db->query();?></p>


The problem is that no update happens in the database.

Can someone help me ?

Thank you to all.
GreyHead 06 Dec, 2009
Hi AndreaZ,

Just to confirm - this is in the Form HTML? Might be better in the OnSubmit code box otherwise the code will be executed whenever the form is viewed.

How do you set $selezione ???

What displays from the echo $query?

Bob
AndreaZ 07 Dec, 2009
You are right.

In any case I have solved adding the sprintf() function.

The code now works. I agree with you and will move the code in the on submit section.


<p><?php $data = date("Y/m/d");
$db =& JFactory::getDBO(); 
// Lancia la query per l'update automatico con la data odierna come DataRisposta
$query = sprintf("UPDATE #__chronoforms_Messaggi_Backend SET DataRisposta = '$data' WHERE cf_id = $selezione");
$db->setQuery($query);
$db->query();
?></p>


Thany you.
This topic is locked and no more replies can be posted.