Hello,
I have a form where I need to save to a DB table.
The question is about saving different field ID inthe same column.
I try to explain:
I have a timestamp field wich needs to go to column DATE
I have a dropbox with 6 values that needs to go to column EVENT
this dropbox switch on and off different field ( checkbox or textbox), whom are the results of the EVENT, and needs to go to column RESULT.
the dropbox switch ONLY ONE result, so the on submit form is alwais a 3 field submission: DATE, EVENT, RESULT.
I don't manage with the action DB save.
Any suggestion?
Thanks
I have a form where I need to save to a DB table.
The question is about saving different field ID inthe same column.
I try to explain:
I have a timestamp field wich needs to go to column DATE
I have a dropbox with 6 values that needs to go to column EVENT
this dropbox switch on and off different field ( checkbox or textbox), whom are the results of the EVENT, and needs to go to column RESULT.
the dropbox switch ONLY ONE result, so the on submit form is alwais a 3 field submission: DATE, EVENT, RESULT.
I don't manage with the action DB save.
Any suggestion?
Thanks
Hello vismay,
I'm not a Chrono professional, but after checking your new post, I think that the following links may help:
How do I save form data to a database table?
P.S: I'm just an automated service😉
I'm not a Chrono professional, but after checking your new post, I think that the following links may help:
How do I save form data to a database table?
P.S: I'm just an automated service😉
Till this explanation everything is clear, but my question was a bit different... I need to save more fields under the same column, not all fields in different tables.
Thanks
Thanks
Hi vismay,
I don't understand what the problem is. If you add a Debugger you can see what data is available to save. Provided that the names there match the columns in the table and the table has a numeric auto-incremented primary key then save should work. If you don't have the primary key then you will need to use a Custom Code action to save the data.
NOTE: you cannot use a form element with the name 'event' as ChronoForms uses this to set the form event to be run.
Bob
I don't understand what the problem is. If you add a Debugger you can see what data is available to save. Provided that the names there match the columns in the table and the table has a numeric auto-incremented primary key then save should work. If you don't have the primary key then you will need to use a Custom Code action to save the data.
NOTE: you cannot use a form element with the name 'event' as ChronoForms uses this to set the form event to be run.
Bob
Thanks for reply:
I'm trying something like this:
But doesn't save to DB.
If I write the sql command in phpmyadmin it records the line... but not through the form.
I'm trying something like this:
<?php
$data = $form->data['data'];
$evento = $form->data['centrali_termiche'];
$1 = $form->data['checkbox_1'];
$2 = $form->data['checkbox_2'];
$3 = $form->data['text_3'];
$db =& JFactory::getDBO();
$query = "INSERT INTO `#__cf_manutenzione` (data, evento, esito) VALUES (('$data'),('$evento'),('$1','$2','$3'));";
$db->setQuery($query);
$db->query();
?>
But doesn't save to DB.
If I write the sql command in phpmyadmin it records the line... but not through the form.
Hi vismay,
There are quite a few mistakes in your code:
+ you can't use $1 as a PHP variable - the name must start with a letter
+ in Joomla! 3.5 it is $db->execute();
+ the syntax for variables in the query is wrong and some of the quotes are too I think.
Please try this version
Bob
There are quite a few mistakes in your code:
+ you can't use $1 as a PHP variable - the name must start with a letter
+ in Joomla! 3.5 it is $db->execute();
+ the syntax for variables in the query is wrong and some of the quotes are too I think.
Please try this version
<?php
$data = $form->data['data'];
$evento = $form->data['centrali_termiche'];
$a = $form->data['checkbox_1'];
$b = $form->data['checkbox_2'];
$c = $form->data['text_3'];
$db = \JFactory::getDBO();
$query = "
INSERT INTO `#__cf_manutenzione` ('data', 'evento', 'esito')
VALUES ( '{$data}', '{$evento}', ('$a','$b','$c') );
";
$db->setQuery($query);
$db->execute();
?>
!! not tested and may need debugging !!
Bob
I was already testing this afternoon, but look like the sql query wants $a OR $b OR $c, only one!
Otherwise throw me an SQL error.
I need to say:
Between these values, write only the one is setted.
Otherwise throw me an SQL error.
I need to say:
Between these values, write only the one is setted.
Hi vismay,
You will need to get the MySQL syntax correct. Adding a Debugger action will show you the MySQL query that is being created.
Bob
You will need to get the MySQL syntax correct. Adding a Debugger action will show you the MySQL query that is being created.
Bob
Hi Bob,
with this code
I get this error:
ERRORE: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''data', 'evento', 'esito') VALUES ( '04/06/16', '', ('','') )' at line 1 SQL=INSERT INTO `#__cf_manutenzione` ('data', 'evento', 'esito') VALUES ( '04/06/16', '', ('','') );
With this code, polished:
I get a similar error:
ERRORE: 1241
Operand should contain 1 column(s) SQL=INSERT INTO `#__cf_manutenzione` (data,evento,esito) VALUES ( '04/06/16', '1', ('Positivo','') );
It waits also the value of $b, but the form is so setted that I get only one value: $a or $b.
with this code
<?php
$data = $form->data['data'];
$evento = $form->data['centrali_termiche'];
$a = $form->data['checkbox_ct'];
$b = $form->data['text_ct'];
$db = \JFactory::getDBO();
$query = "
INSERT INTO `elhi5_cf_manutenzione` ('data', 'evento', 'esito')
VALUES ( '{$data}', '{$evento}', ('$a','$b') );
";
$db->setQuery($query);
$db->execute();
?>
I get this error:
ERRORE: 1064
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''data', 'evento', 'esito') VALUES ( '04/06/16', '', ('','') )' at line 1 SQL=INSERT INTO `#__cf_manutenzione` ('data', 'evento', 'esito') VALUES ( '04/06/16', '', ('','') );
With this code, polished:
<?php
$data = $form->data['data'];
$evento = $form->data['centrali_termiche'];
$a = $form->data['checkbox_ct'];
$b = $form->data['text_ct'];
$db = \JFactory::getDBO();
$query = "
INSERT INTO `elhi5_cf_manutenzione` (data,evento,esito)
VALUES ( '$data', '$evento', ('$a','$b') );
";
$db->setQuery($query);
$db->execute();
?>
I get a similar error:
ERRORE: 1241
Operand should contain 1 column(s) SQL=INSERT INTO `#__cf_manutenzione` (data,evento,esito) VALUES ( '04/06/16', '1', ('Positivo','') );
It waits also the value of $b, but the form is so setted that I get only one value: $a or $b.
I've soved with something like this:
Thanks a lot anyway to let me think and find solutions!
<?php
$data = $form->data['data'];
$evento = $form->data['caldaie'];
if(empty($_POST['text_ct']))
{
$esito = $form->data['checkbox_ct'];
}
if(!empty($_POST['text_ct']))
{
$esito = $form->data['text_ct'];
};
$db =& JFactory::getDBO();
$query = "INSERT INTO `elhi5_cf_manutenzione` (data, evento, esito) VALUES (('$data'),('$evento'),('$esito'));";
$db->setQuery($query);
$db->query();
?>
Thanks a lot anyway to let me think and find solutions!
Now I have an interesting question:
The code:
INSERT only a record, its' possible to update the record if the string $evento is already in database?
I have no ID, only 3 colums.
Thanks
The code:
<?php
$data = $form->data['data'];
$evento = $form->data['caldaie'];
if(empty($_POST['text_ct']))
{
$esito = $form->data['checkbox_ct'];
}
if(!empty($_POST['text_ct']))
{
$esito = $form->data['text_ct'];
};
$db =& JFactory::getDBO();
$query = "INSERT INTO `elhi5_cf_manutenzione` (data, evento, esito) VALUES (('$data'),('$evento'),('$esito'));";
$db->setQuery($query);
$db->query();
?>
INSERT only a record, its' possible to update the record if the string $evento is already in database?
I have no ID, only 3 colums.
Thanks
Hi vismay,
Yes I expect so. But this is a MySQL question.not a ChronoForms one,
Bob
Yes I expect so. But this is a MySQL question.not a ChronoForms one,
Bob
This topic is locked and no more replies can be posted.