Save data in separate database

jxl 22 Mar, 2008
Is it possible to use ChronoForms to save submitted data in a database other than the Joomla Database? I hope to have quite a lot of data that I want to keep separate from my Joomla installation.

I think that given a few days and and using some example php forms that I have access to, I could figure out how to write a form that uses php to write to a particular database, then put all that code into the form html.(maybe :blink: :unsure: )

But I would like to know if there is any way to just connect chronoforms to another database and have it write the tables, be able to export excel or CSV and/or show saved data.

I'm sure I will need help with displaying the data on the front end too but I won't ask till I've had a chance to read more on the forum.
GreyHead 22 Mar, 2008
Hi jxl,

I'm sure it's possible, I think that it will work if you put appropriate code in the Autogenerated code tab.

Bob
Max_admin 22 Mar, 2008
Hi Jxl,

Search google for PHP code to connect to another database and insert data, this should be easy!

Cheers

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
jxl 22 Mar, 2008
Thanks to both of you. It won't be easy for me because I don't know what the heck I'm doing...But I'll do a search and figure something out. I'll probably ask more specific questions when I get further along.
Thanks for taking the time to answer.

Oh, one more thing. Since you brought it up, when would I use the autogenerated code tab rather than putting php into the html tab?<br><br>Post edited by: jxl, at: 2008/03/22 04:03
GreyHead 22 Mar, 2008
Hi jxl,

ChronoForms has four boxes that you can put code into. In sequence they are:
[list]
  • Form HTML - php here is executed when the form page is loaded, all other code is executed on submission
  • 'OnSubmit before email' - code is only executed if 'Send email' is on.
  • 'OnSubmit after email' - runs whether or not 'Send email' is on
  • 'AutoGenerated code - prepopulated when you click the Create Table link
  • [/list]Technically, all four behave in exactly the same way, they execute any php and display the results and any html.

    Which you use depends on what you want to do. You use Form HTML if you want to dynamically change the form itself; OnSubmit before if you want to change the email contents; OnSubmit after if you want to change the saved data or the 'Thank You page', or to send a second email; Autogenerated code you should generally leave alone unless you want to change the way data is saved in the ChronoForms table.

    Bob
    jxl 23 Mar, 2008
    Thank you Bob. That clears it up nicely!
    jxl 25 Mar, 2008
    Bob and Max, I got it working!!!
    For anyone else that wants to do this,AND for anyone that has comments on whats wrong with this method (maybe some security problems or whatever?)
    Here is what I did:

    Made the form.
    Since it was a very long form i had Chronoforms make the tables in my Joomla database. I then exported that table and imported it into my outside database. I deleted the tables from the joomla database.
    Now I have my table with all its columns set up in my desired database.

    Next, I deleted the Autogenerated code from the Chronoforms form and added the following code (actually this is a short version, my real form had many, many more fields)

    Autogenerated code:
    <?php
    $con = mysql_connect("localhost","MyDatabase","MyPassword"«»);
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("MyDatabase", $con);
    
    $sql="INSERT INTO my_table(your_name,your_address,your_state)
    VALUES
    ('$_POST[your_name]','$_POST[your_address]','$_POST[your_state]')";
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
    
    mysql_close($con)
    ?>
    The e-mail works and the data goes into my database.
    I haven't figured out form validation yet though. I'm not sure if I'm doing it wrong or if something about my php is messing with it.

    Edited to add code tags.<br><br>Post edited by: GreyHead, at: 2008/03/25 10:15
    This topic is locked and no more replies can be posted.

    VPS & Email Hosting 20% discount
    hostinger