Forums

Posting to Database stopped working with external view Help

4square 08 Mar, 2010
I've purchased both Chrono Forms and Connectivity. I had my quote request form up and running in 30 minutes! Very good plug-in.

My problem is the following. I created a second form for approved users to upload a small text file and I wrote php to parse the data and to get the additional information and geocode the addresses. That was working just fine. I had a problem getting the map to display so I created a different page for debugging purposes to see if the problem was happening inside the article content or if there was an error in my logic. After I did that, the input form no longer writes the data to the table.

This has been an arduous process since I'm no expert in php and there are only bits of information in these posts. I've been doing LOTS of reading on these forums and trying to figure out where each bit goes has been an issue. I don't know where to go from here.

This is the code that the index.html page calls outside of joomla http://www.sheboyganhomeinspector.com/radon

<?php
//createmarkers.php
//use this file to create an xml file from table radon_tests to map

require("dbinfoj.php");

function parseToXML($htmlStr) 
{ 
$xmlStr=str_replace('<','<',$htmlStr); 
$xmlStr=str_replace('>','>',$xmlStr); 
$xmlStr=str_replace('"','"',$xmlStr); 
$xmlStr=str_replace("'",''',$xmlStr); 
$xmlStr=str_replace("&",'&',$xmlStr); 
return $xmlStr; 
} 

// Opens a connection to a MySQL server
$connection=mysql_connect ($hostname, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table
$query = "SELECT * FROM $table WHERE lat>0";
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Start XML file, echo parent node
echo '<markers>';

// Iterate through the rows, printing XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  echo '<marker ';
  echo 'name="' . parseToXML($row['inspector']) . '" ';
  echo 'lat="' . $row['lat'] . '" ';
  echo 'lng="' . $row['lng'] . '" ';
  echo 'epa_avg="' . $row['epa_avg'] . '" ';
  echo 'type="' . $row['m_type'] . '" ';
  echo '/>';
}

// End XML file
echo '</markers>';
mysql_close($connection);
?>


I first tried placing the index code in an article. The map would show up but the overlay marker data would not appear. I unpublished that article and put the files in an alternate directory outside of joomla and it works fine there. But as I mentioned, the update form will not write additional data to the radon_tests table. I can use the form, enter data submit the data. The file uploads, DEBUG ON reports everything is OK. The variables are correct. I don't know where to go from here.


Any suggestions?
Thank you
GreyHead 08 Mar, 2010
Hi 4square;

If I understand correctly the core of the problem is that your 'test' form isn't saving data to the database. There really isn't much to this, provided that the DB Connection is set up to a valid table and the column names match the form input names this works very smoothly.

By all means PM or Email me a Superadmin login and I'll take a quick look if that would help - you can't tell much from the front-end views.

Adding Google Maps is quite tricky. I did quite a complex app using maps linked to a db table a while ago and it took a lot of head scratching to get it to work. I found Mike Reumer's Google Maps extension for Joomla very helpful.

Bob
4square 10 Mar, 2010
Thank you so much for your help! My programming experience goes all the way back to DOS and Paradox. I'm pretty good at logic and but still trying to learn the correct PHP and MySQL syntax. I'm pretty much clueless with javascript at this point. I've been doing lots of reading and trying and I appreciate your expertise! I did contact Mike Reumer and will look at that plug-in. It's been a busy all day doing the core of my business but I did want to let you know that I looked at what you did.

I'm scratching my head a little. I like the ability that ChronoForms has to process code, but if I link to the map page as a menu item it doesn't seem to work. The link by itself works fine and I added more data to the radon table and the new icons do appear as they should.

I can't wait for you to get your ChronoForms book done!

Greg
GreyHead 10 Mar, 2010
Hi Greg,

Just took a quick look and I think that the non-display from the menu is probably a side effect of the SEO Urls. Some url is being broken - FireBug shows three GETs from the page that aren't executing properly and one of them is 'changemarkers.php'.

Bob
4square 12 Mar, 2010
I have no idea how to fix that one. I posted a "static link" and that seems to work for now. But I think you're right because if I attach the link to a menu item it stops working. I didn't think this would be as frustrating as it has become. I hope to be in contact with Mike sometime this weekend.
Thanks
GreyHead 12 Mar, 2010
Hi Greg,

As you see, the link within the article isn't the same. It's been 'changed' to an SEO version somewhere along the road. The SEO version is {domain}/component/chronocontact/ . . .

The actual problem is that somewhere deep inside the map code a file called changemarkers.php is being loaded. The correct address of this file is {domain}/changemarkers.php

However the calling code uses a relative address and so when the SEO version of the URL is in use it tries to load {domain}/component/chronocontact/changemarkers.php and fails as that file doesn't exist.

I guess the right answer to this is to find the call to the file and change it to an absolute url. But I can't seen where it is, the immediate call is from the depths of the google maps api code.

Bob
4square 12 Mar, 2010
Ok, that pointed me in the right direction. In the JavaScript section of the form I made the following change:
GDownloadUrl("createmarkers.php", function(data) {...

to
GDownloadUrl("http://sheboyganhomeinspector.com/createmarkers.php", function(data) {...


It's not the cleanest, but as long as domain doesn't change this works. I never would have figured that out without your help. Thanks!
GreyHead 12 Mar, 2010
Hi Greg,

Ah well found.

You may find that
GDownloadUrl("/createmarkers.php", function(data) {...
with the added / will work - usually that forces a URL relative to the domain root but I'm not sure how it will behave with the SEO URLs.

bob
4square 13 Mar, 2010
That works! It's amazing how important one little character can be. 😀 Now I think I'm ready to start phase 2 with a zipcode lookup on the main form. Thanks!
This topic is locked and no more replies can be posted.