Database Connection:Connecting more than one table

muskan 06 Mar, 2009
Hello bob
Have posted my query earlier also. You have given me link to php codes used in joomla. Have tried those codes but i am unable to connect o databse using php codes. Have gone through various other similar query as well. Have run those codes as well but of no use.......
Could you please write a sample code for me to connect to databse. I have my jos_chronoform_intro_from saved in jos_ folder of mysql in xampplite.
Pls giv me database connection, php codes for it that cn be run on joomla using chronoforms

    <?php
        <?php
        $options = array('host' => 'localhost', 'user' => 'root', 'password' => '', 'database' => 'jos_', 'prefix' = '', 'select' => 'jos_chronoforms_intro_form');
        $db2 =& new JDatabaseMySQL($options);
        ?>
            $db2->setQuery("insert into `jos_chronoforms_intro_form` (`Name`,`City`) values('tanvi','19');");
    ?>


Or pls find the error in above code, have seen this code in one of the other posts, there the person hs written that it works but its nt inserting values in my table
Regards
GreyHead 06 Mar, 2009
Hi muskan,

Where is the database? There aren't any other PHP codes to try . . . this code just calls the standard PHP.

Bob
muskan 06 Mar, 2009
Hello
I didn't understand the meaning of your question...where is the database??....I have database on xampplite server. Server is running offline as localhost. The forms are stored in xamplite->mysql->data->jos_->jos_Chronoforms_intro_form
But i am unable to insert any new entry into it using php codes..!! 😟
And what do you mean by just calls the standard php....is the code i have written above will not insert values into the table??
muskan 06 Mar, 2009
hello
Someone please help me....am getting fed up now....have stuck on this for over a week now....!!!...is there any solution or i have to drop joomla and chronoforms and should start building a website from sctratch...
GreyHead 06 Mar, 2009
Hi muskan,

Well the code you have here looks a bit odd, almost certainly the two <?php <?php tags will cause an error. Try this:
<?php
$options = array( 'host' => 'localhost', 'user' => 'root', 'password' => 'xxxxxxxx', 'database' => jos_', 'prefix' = 'jos_', 'select' => 'jos_chronoforms_intro_form' );
$db2 =& new JDatabaseMySQL($options);
$db2->setQuery("insert into `#__chronoforms_intro_form` (`Name`,`City`) values('tanvi','19');");
$db2->query();
?>
You then need to replace both xxxxxxxx with the correct values.

Why do you need a second database? Can't you just put the table in the Joomla database, they must both be on the same MySQL setup?

Bob
muskan 07 Mar, 2009
Hello Bob
Thanx for the reply....
Actually I need two tables from single form....one i have already connected using chronoform DB connection form and second I need to do using php coding....
And have removed one php tag code is still not working..!!...Now am wondering whether am writing the code in correct area of chronoforms form code ?? Where are we required to put these php codes in chronoform??....in form code section in OnSubmit area???....And is there any enable option to be set yes for enabling php written in OnSubmit to be executed like we have for storage enable in chronoform inbuilt form??.
GreyHead 07 Mar, 2009
Hi muskan,

You don't need a second database connection to connect to a second table in the same database. The standard Joomla connection will work OK with *all* the tables in the database. Here's your code re-written for the standard database
<?php
$db =& JFactory::getDBO();
$query = "
  INSERT
    INTO `#__chronoforms_intro_form` (`Name`,`City`) 
    VALUES ('tanvi', '19') ;
";
$db->setQuery($query);
$db->query();
?>

You can put the code in (a) the Form HTML box, (b) the OnSubmit Before Box or (c) the OnSubmit After box. Which you use depends on what you need to do. Use (a) to include information in the form, use (b) to include information in the email (though there are some small problems with this), use (c) to include information in the databse or the thank you page.

Bob
muskan 08 Mar, 2009
Hello Bob
Thanx for your reply...
I have pasted the code provided by you as it is in form html area ......but still values are not getting inserted into intro_form.....😟
GreyHead 08 Mar, 2009
Hi muskan,

That sounds right . . . what do you actually want this code to do?

Bob
muskan 10 Mar, 2009
Hello Bob
Actually I want to insert values into chronoforms_intro_form after drop_list form is submitted. So need to use sql queries to insert values into this intro form.
GreyHead 10 Mar, 2009
Hi Muskan,

Ok - so the code needs to go in one of the OnSubmit boxes, probably the After one.

To debug, add a line to echo $query so that you can see exactly what is being run; I usually test this by pasting it into EasySQL to see if the syntax is good.

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