Page 1 of 1
access data from one database with a page created with another
Posted: Fri Jan 06, 2006 9:15 pm
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.
Re: access data from one database with a page created with another
Posted: Fri Jan 06, 2006 9:31 pm
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';
}
Re: access data from one database with a page created with another
Posted: Fri Jan 06, 2006 9:43 pm
by outdoorxtreme1
This code worked on my old site before converting to CMS. Just trying to get it working with CMS now.
Re: access data from one database with a page created with another
Posted: Fri Jan 06, 2006 10:47 pm
by Ted
Url should be: /index.php?page=Trip_Log_Report&trip=37
Re: access data from one database with a page created with another
Posted: Sun Jan 08, 2006 4:59 am
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");
}
Re: access data from one database with a page created with another
Posted: Sun Jan 08, 2006 6:42 pm
by calguy1000
I'm not sure, but replacing your include statement with a header(blah) statement might work.