Insert in a different table

GM GMiranda 02 Jan, 2012
Hello,

I suppose my question is simple, but I can't solve it:
I need to insert a new record in a table different from the one the Form is connectet to.
The value will be a field in the form.
But I cannot just INSERT anything in the second table (my_table).

I have done this simple test, put in the Submit section:
<? 
$db = &JFactory::getDBO(); 
$query = "INSERT INTO my_table (tema) VALUES ('Ciao')";
$db->setQuery($query);
?>


Any idea?

Thanks in advance,
Gonzalo Miranda
Gr GreyHead 08 Jan, 2012
Hi GMiranda,

You also need to include the line of code to execute the query, setQuery() only sets it :
<?
$db = &JFactory::getDBO();
$query = "INSERT INTO `my_table` (`tema`) VALUES ('Ciao')";
$db->setQuery($query);
$db->query(); // <-- add this line
?>

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