access data from one database with a page created with another

For questions and problems with the CMS core. This board is NOT for any 3rd party modules, addons, PHP scripts or anything NOT distributed with the CMS made simple package itself.
Locked
outdoorxtreme1

access data from one database with a page created with another

Post by outdoorxtreme1 »

I am using CMS made simple. Is it possible to get data from one database from a page that is created from another? I have a link like this:
/index.php?page=Trip_Log_Report?trip=37

and it tells me that my page cannot be found.
outdoorxtreme1

Re: access data from one database with a page created with another

Post by outdoorxtreme1 »

I have made a page with a user-defined tag called: Trip Log Report

Here are the contents:
{triplogreport}

Here is the tag I am trying to use:

$host = "localhost";
$user = "username";
$pass = "password";
$dbname = "dbname";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."");
mysql_select_db($dbname);

if (is_numeric($_GET['trip'])) {
$tripdetail = $_GET['trip'];
} else {
echo 'that is not a number';
die;
}

$sql = 'SELECT * FROM trip_log WHERE trip_id=' . $tripdetail;
$result = mysql_query($sql) or die ('select died: ' . mysql_error());

while ($row = mysql_fetch_array($result)) {
$startdate = date("F d, Y",$row['startdate']);
$enddate = date("F d, Y",$row['enddate']);
echo '',$row['triplocation'],', ',$row['state'],'';
echo '';
echo $startdate;
if ($enddate!= $startdate) echo ' to ',$enddate;
echo '';

if (!empty($row['riverclass'])) echo 'River Class: ',$row['riverclass'],'';
if (!empty($row['rivercondition'])) echo 'Water Level: ',$row['rivercondition'],'';
if (!empty($row['GaugeID'])) echo 'USGS Gauge Info: ',$row['GaugeID'],'';
if (!empty($row['GaugeFT'])) echo 'USGS Gauge Height: ',$row['GaugeFT'],'';
if (!empty($row['GaugeCFS'])) echo 'USGS Flow: ',$row['GaugeCFS'],'';
if (!empty($row['triporganizer'])) echo '';
if (!empty($row['triporganizer'])) echo 'Trip Organizer: ',$row['triporganizer'],'';
if (!empty($row['p1'])) echo '';
if (!empty($row['p1'])) echo 'Participant Names:';
if (!empty($row['p1'])) echo ,$row['p1'],'';
if (!empty($row['p2'])) echo ,$row['p2'],'';
if (!empty($row['p3'])) echo ,$row['p3'],'';
if (!empty($row['p4'])) echo ,$row['p4'],'';
if (!empty($row['p5'])) echo ,$row['p5'],'';
if (!empty($row['p6'])) echo ,$row['p6'],'';
if (!empty($row['p7'])) echo ,$row['p7'],'';
if (!empty($row['p8'])) echo ,$row['p8'],'';
echo '';
echo 'Trip Report:';
echo '',$row['report'],'';
echo '';
echo 'Trip Report Author: ',$row['author'],'';
echo '';
echo '';
echo '
Back';
}
outdoorxtreme1

Re: access data from one database with a page created with another

Post by outdoorxtreme1 »

This code worked on my old site before converting to CMS. Just trying to get it working with CMS now.
Ted
Power Poster
Power Poster
Posts: 3329
Joined: Fri Jun 11, 2004 6:58 pm

Re: access data from one database with a page created with another

Post by Ted »

Url should be: /index.php?page=Trip_Log_Report&trip=37
outdoorxtreme1

Re: access data from one database with a page created with another

Post by outdoorxtreme1 »

Thanks alot. That worked. I have one more problem that I can't seem to figure out. I am trying to include a page on a submit if error are found on the form page. Are you able to help me with this?
The page just shows up blank if there are errors instead of including the form page

Here is the tag I am trying to get to work.


// initialize var for storing possible error messages
$errmsg = '';

// check rivername
if (empty($_POST['triplocation'])) {
$errmsg .= 'Your report has no [ATV area]';
}

// check state
if (empty($_POST['state'])) {
$errmsg .= 'Your report has no [state]';
}

// check author
if (empty($_POST['author'])) {
$errmsg .= 'Please identify the [trip report author]';
}

// check report
if (empty($_POST['report'])) {
$errmsg .= 'Please fill in your [trip report]';
}

// check to see if anything was placed in our error var, meaning there was an error
if (!empty($errmsg)) {

include  '/index.php?page=ATVing_Form';

} else {
$host = "localhost";
$user = "neohoutd_nsutika";
$pass = "72spoke";
$dbname = "neohoutd_data";

$connection = mysql_connect($host,$user,$pass) or die (mysql_errno().": ".mysql_error()."");
mysql_select_db($dbname);

$startdate = mktime(0,0,0,$TSpickMonth,$TSpickDay,$TSpickYear);
$enddate = mktime(0,0,0,$TFpickMonth,$TFpickDay,$TFpickYear);

$sql_query = mysql_query("INSERT INTO trip_log(triptype, triplocation, state, rivercondition, riverclass, triporganizer, GaugeFT, GaugeCFS, GaugeID, author, email, p1, p2, p3, p4, p5, p6, p7, p8, report, photolink, videolink1, videolink2, videolink3, miles, startdate, enddate) VALUES ('$triptype', '$triplocation', '$state', '$rivercondition', '$riverclass', '$triporganizer', '$GaugeFT', '$GaugeCFS', '$GaugeID', '$author', '$email', '$p1', '$p2', '$p3', '$p4', '$p5', '$p6', '$p7', '$p8', '$report', '$photolink', '$videolink1', '$videolink2', '$videolink3', '$miles', '$startdate', '$enddate')")
or die (mysql_error());

header("Location: /index.php?page=Trip_Log");
}
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

Re: access data from one database with a page created with another

Post by calguy1000 »

I'm not sure, but replacing your include statement with a header(blah) statement might work.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Locked

Return to “CMSMS Core”