Forums

Using a db field in the mail

puni_toice 29 Dec, 2011
Hello together,

after writing the database, I have another SQL update and create a new keyfield. In the mail to the customer I'd like to sent this key. But How can I get this - my problem is to get the right record.

Can you help me?
GreyHead 29 Dec, 2011
Hi puni_toice,

Which version of ChronoForms are you using? You can find the version from Site Admin | Extensions | Install/Uninstall | Components in Joomla! 1.5 or Site Admin | Extensions | Extension Manager | Manage in Joomla! 1.6.

How are you creating the new keyfield? Is it an autoincremented primary key? If you are using the ChronoForms DB Save or DB Connection the value is saved for you. If you are using your own custom code for the query then I think you can get it from the query response.

Bob
puni_toice 29 Dec, 2011
I did it :-) I Use the Version 4.0 RC1.9. Joomla 1.7.2

I made it with a SQL in the mail and with a status. When I´m writing the key the status is null. Then I take the record with the null status, write the mail and the next step is to change the status, but this can be a problem if two people make it in the same time. But it´s only a risk for a second. But it´s more save when I can take the unique key which chronoforms is writing.

But I have an other stupid problem..with my SQL´s - this one is the first for creating the key. It´s the same db - I make it in the db which saved the form results.

This one ist working
<?php
$con = mysql_connect("localhost",user","pw");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db", $con);

mysql_query("UPDATE `jos_chronoforms_data_last` SET `key` = CONCAT (SUBSTRING(cf_created,6,2), SUBSTRING(cf_created,9,2), SUBSTRING(cf_uid, 10,6)) WHERE `status` IS NULL");

mysql_close($con);
?> 


when I change it like this, it doesn't
<?php
$db  =& JFactory::getDBO();

$query =("UPDATE `jos_chronoforms_data_last` SET `key` = CONCAT (SUBSTRING(cf_created,6,2), SUBSTRING(cf_created,9,2), SUBSTRING(cf_uid, 10,6)) WHERE `status` IS NULL");
$db->setQuery($query);  
?> 
GreyHead 30 Dec, 2011
Hi puni_toice,

The $db->setQuery() only sets the query, it doesn't run it.
<?php
$db  =& JFactory::getDBO();
$query = "
  UPDATE `#__chronoforms_data_last` 
    SET `key` = CONCAT (SUBSTRING(cf_created, 6, 2), SUBSTRING(cf_created, 9, 2), SUBSTRING(cf_uid, 10, 6)) 
    WHERE `status` IS NULL;
";
$db->setQuery($query); 
$db->query(); // <-- add this line
?>

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