Forums

Use external Database

adolf 20 Feb, 2011
Hello,

i want to use a external Database to save the data? Who can I do this?

Best Regardings adolfo
GreyHead 20 Feb, 2011
Hi adolf,

There's a how-to document that covers connecting to a second database here. You'll need to hand-code the save in one of the OnSubmit code boxes - but you can use ChronoForms AutoGenerated code as the basis for this.

Bob
adolf 22 Feb, 2011
Hi Greyhead,

thank you. But where must i put this code to save the form in another database?

<?php
$options = array(
'host' => 'xxx',
'user' => 'xxx',
'password' => 'xxx',
'database' => 'xxx',
'prefix' = 'xxx',
'select' => true
);
$db2 =& new JDatabaseMySQL($options);
?>


adolf
GreyHead 22 Feb, 2011
Hi adolf,

You will need to put this plus the code to save the form data into one of the OnSubmit code boxes.

Bob
adolf 22 Feb, 2011
How is the code to save the form?
Can I use the $_POST var?

$db2->setQuery("INSERT INTO table (field1,field2) VALUES ('".$_POST['field1']."', '".$_POST['field2']."') ");

Thank you🙂
GreyHead 22 Feb, 2011
Hi adolf,

Yes, that will do it. Or you could adopt the Table Class based method used by ChronoForms if you want to be a little more flexible.

Bob
adolf 23 Feb, 2011
hi,

is used the following code but it does not work. Can you help me?

<?php

$dbserver   = "84.165.196.100";
$dbbenutzer = "the_user";
$dbpasswort = "pw";
$dbselected = "db01";
mysql_connect($dbserver,$dbbenutzer,$dbpasswort);
mysql_select_db($dbselected); 
mysql_query("INSERT INTO kontakte (vorname,kundenname) VALUES ('".$_POST['vorname']."', '".$_POST['kundenname']."') ");

$options = array(
'host' => '88.165.196.100',
'user' => 'the_user',
'password' => 'pw',
'database' => 'db01',
'prefix' = '',
'select' => true
);
$db2 =& new JDatabaseMySQL($options);
$db2->setQuery("INSERT INTO kontakte (vorname,kundenname) VALUES ('".$_POST['vorname']."', '".$_POST['kundenname']."') ");
?>


In On Submit code - before sending email:(May contain PHP code with tags)
GreyHead 23 Feb, 2011
Hi adolf,

Exactly what is not working?

I'd suggest that you echo out the queries and check them with PHPMyAdmin.

You have got different IP addresses for the server in the two database connections. Is this correct?

Bob
adolf 23 Feb, 2011
Hello,

the first bug was a lost > after prefix.

<?php
$options = array(
'host' => '88.165.196.100',
'user' => 'the_user',
'password' => 'pw',
'database' => 'db01',
'prefix' => '',
'select' => true
);
$db2 =& new JDatabaseMySQL($options);
$db2->setQuery("INSERT INTO kontakte (vorname,kundenname) VALUES ('".$_POST['vorname']."', '".$_POST['kundenname']."') ");
?>


If I add a "echo 'test';" at the second line i didnt can see it.
adolf 24 Feb, 2011
hi,

there must be an another bug. It doenst work.

Can i check the connection? Or make a test echo?
kalei 24 May, 2011
You were pretty close…
you set your query but you never executed it 🤣
so just add one row
$db2->query();
and then everything should work fine (except your chosen nickname, dude change that…)
This topic is locked and no more replies can be posted.