Forums

Strange query

maximus 08 Apr, 2009
Hi,

I've used the chronoform component for several Forms on my website. It really helps me making forms quite fast! But now I have a problem I couldn't solve.

I've made a form to store some given in article in a database which is not the joomla-database. The code is below. For some strange reason, when I submit a "news"-article everything works fine. But when I try to submit an "upcoming"- or "link"-article I get some errors from MySql that my syntax isn't correct. Okay then, I will check the syntax of my query by simply echoing it. But the query I've made for a "upcoming"- or "link"-article isn't the query I've made! Instead of
INSERT INTO events_table (`date`, `data`, `image`) VALUES ('$date', '$data', '$image');
I get
SELECT * FROM #__chrono_contact_plugins WHERE form_id='12' AND event='ONSUBMIT' AND name="
. What is going wrong here?

Thanks in advance!

Code (Because I assume that are my variables are properly initialized, I only post the processing-part and not the layout of my form)(The code is placed at the "On Submit code - after sending email"-part of the form) :

<?php
	$category = $_POST['select_4'];
	$title = $_POST['text_11'];
	$date = $_POST['text_8'];
	$image = $_POST['text_10'];
	$data = $_POST['text_9'];
	
	switch ($category)
	{
		case "news":
			$query = "INSERT INTO news_table (`date`, `data`, `image`, `title`) VALUES ('$date', '$data', '$image', '$title');";
			break;
		case "upcoming":
			$query = "INSERT INTO events_table (`date`, `data`, `image`) VALUES ('$date', '$data', '$image');";
			break;
		case "link":
			$query = "INSERT INTO link_table (`title`, `link`) VALUES ('$title', '$data');";
			break;
	} 
        echo $query;
		$selectResult = mysql_select_db("X" ) or die                      	('Error switching db'.mysql_error());
        $result= mysql_query( $query ) or die                      	('Error Inserting'.mysql_error());
        $selectResult = mysql_select_db("JOOMLA_DATABASE" ) or die                      	('Error switching db back'.mysql_error()); 
         echo "Article submitted!";


?>
Max_admin 09 Apr, 2009
Hi,

Which Chronoforms version is this ? try to use your code with V3.1 RC4 and I think it should work fine, or simple change the variable $query in your code to something else, like $myquery

Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
GreyHead 09 Apr, 2009
Hi Maximus,

Your switch doesn't have a default setting so if the category isn't 'news', 'upcoming' or 'link' then the last value of $query is used which happens to be one of the internal ChronoForms queries.

Joomla will quite happily connect to more than one database - the code is in the forums here, try searching on db2

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