Insert data on submit?

PicoPaco 28 Jun, 2010
Hi,

I try to put some information into my database after submit. What I want to do is to get some data from another table to store in this table as well. I have tried to do this in the field "On Submit code - after sending email", but it doesn't seem to work.


<?php
$dnr = JRequest::getString('dnr');
$id_nr = JRequest::getString('id');

$db =& JFactory::getDBO();

$query = "
  SELECT ".$db->nameQuote('iso')."
    FROM ".$db->nameQuote('upphandling')."
    WHERE ".$db->nameQuote('dnr')." = ".$db->quote($dnr).";
  ";

$db->setQuery($query);
$iso = $db->loadResult();

$query2 = "UPDATE avtal SET iso=$iso WHERE id='$id_nr'";
$db->setQuery($query2);

?>


Do any one know what I am doing wrong or have any other soulution to my problem?


Thanks,

Markus
GreyHead 28 Jun, 2010
Hi PicoPaco,

You aren't executing the second query
$db->setQuery($query2);
$db->query(); // <-- add this line 
?>

Bob
PicoPaco 28 Jun, 2010
Hi Bob,

When I add this line ($db->query2();) I just get a white page. I believe that is bacause the $id_nr dosn't exist yet in the table. Do you know any other way to do this?

The reason I want to store the same information in this table as in the 'upphandling'-table is because I want to be able to filter on this information later in CC.

Regards

Markus
GreyHead 28 Jun, 2010
Himarkus,

But that is different from the code I posted :-(

Bob
PicoPaco 28 Jun, 2010
Hi Bob

Yes I thought that I should execute query2(), but I tried $db->query(); too. There were no problem to execute this, but it didnt update the table.

Thanks

Markus
GreyHead 28 Jun, 2010
Hi Markus,

Output the $query2 string and check what it looks like.

Bob
PicoPaco 29 Jun, 2010
Hi Bob,

I see now that there are no value in $id_nr, and i guess that is because the CF-query have not been executed yet when the "On Submit code - after sending email:" is executed. Any idea what to do?


Thanks for your help Bob
GreyHead 10 Jul, 2010
Hi PicoPaco,

Sorry, very late getting back to this. You need to change the Run Order so that the OnSubmit After code is after the Autogenerated code.

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