Trouble with database link - SORTED

I have a details page with information and images on it from a database as well as a calander. The calender has links to the previous and next Years

[php]Year: <a href="<?=(date("Y", time()) < $year) ? $PHP_SELF."?year=".($year-1)."&plan_nr=$plan_nr$get" : ""?>">
<?=(date("Y", time()) < $year) ? $year-1 : ""?>
[/php]

[php]Year: <a href="<?=$PHP_SELF."?aptRef=".$row_listing['aptRef']."?year=".($year+1)."&plan_nr=$plan_nr$get"?>">
<?=$year+1?>
[/php]

When I click on these links it does what it supposed to but I lose all the details on the page.

I have tried

[php]Year: <a href="<?=$PHP_SELF."?aptRef=". $row_listing['aptRef'] ."?year=".($year+1)."&plan_nr=$plan_nr$get"?>">
<?=$year+1?>[/php]

This keeps the information but doesnt progress the calander.

Any Suggestions anyone

First off I see a security problem…

You shouldn’t be able to use $PHP_SELF, as this would mean Global variables are turned on, and that is a security risk. $_SERVER[‘PHP_SELF’] is what should be used with global variables turned off.

As far as losing data you need to keep the data stored in some way. Whether that be re-pulling it from the database, storing in the url or something.

Well maybe I should ask, how does the data get there in the first place?

the data is pulled from the database as follows

[php]mysql_select_db($database_connect, $connect);
$query_listing = “SELECT * FROM listings WHERE aptRef = ‘$aptRef’”;
$listing = mysql_query($query_listing, $connect) or die(mysql_error());
$row_listing = mysql_fetch_assoc($listing);
$totalRows_listing = mysql_num_rows($listing);
include(“users/ListCfg/”.$row_listing[‘aptRef’].".php");[/php]

the line

[php]include(“users/ListCfg/”.$row_listing");[/php]

is a static page I learnt how to do from this forum see

http://phphelp.com/forums/viewtopic.php?t=7461&highlight=

This files contains the details for the selected apartment

While the database contains contact information and the apartment ref

The calander is pulled by the following

[php]
header(“Expires: “.gmdate(“D, d M Y H:i:s”).” GMT”);
header(“Last-Modified: “.gmdate(“D, d M Y H:i:s”).” GMT”);
header(“Cache-Control: no-cache, must-revalidate”);
header(“Pragma: no-cache”);
header(“Cache-Control: post-check=0, pre-check=0”);

$month = array( “01” => “January”,
“02” => “February”,
“03” => “March”,
“04” => “April”,
“05” => “May”,
“06” => “June”,
“07” => “July”,
“08” => “August”,
“09” => “September”,
“10” => “October”,
“11” => “November”,
“12” => “December”
);

$v_month = array( “01” => “Jan”,
“02” => “Feb”,
“03” => “Mar”,
“04” => “Apr”,
“05” => “May”,
“06” => “Jun”,
“07” => “Jul”,
“08” => “Aug”,
“09” => “Sep”,
“10” => “Oct”,
“11” => “Nov”,
“12” => “Dec”
);

if (!$dbh = @mysql_connect($db_addr, $db_user, $db_pass)):
die (“Connection to the data base server could not be made.”);
endif;

if (!$dbdat = @mysql_select_db($db_name, $dbh)):
die (“Unable to establish a connection to the database.”);
endif;

function table_exists($table) {
GLOBAL $db_name;
$result = mysql_list_tables ($db_name);
if (!$result) {echo "Examination of the tables could not be accomplished.
";}
else {
while($row = mysql_fetch_row($result)){
if ($row[0] == $table) return true;
} }
return false;
}

function check_date($d, $m, $Y){

if (date(“m-d-Y”, mktime(0, 0, 0, $m, $d, $Y)) == “$m-$d-$Y”) return true;
return false;
}

function daysinmonth($month, $year)
{
if(checkdate($month, 31, $year)) return 31;
if(checkdate($month, 30, $year)) return 30;
if(checkdate($month, 29, $year)) return 29;
if(checkdate($month, 28, $year)) return 28;
return 0; // error
}

function weeksinmonth($month, $year){
$firstDey = array (“01”, $month, $year);
$lastDey = array (daysinmonth($month, $year), $month, $year);
$tst1 = mktime (1, 0, 0, $firstDey[1], $firstDey[0], $firstDey[2]);
$tst2 = mktime (1, 0, 0, $lastDey[1], $lastDey[0], $lastDey[2]);
$wa = date(“W”, $tst1);
$we = date(“W”, $tst2);
if ($wa == 53) $wa = 1;
$weeks = $we - $wa;
return array($weeks, $wa, $we);
}

function get_time ($tst){
Global $timestring;
$lok = date($timestring, $tst);
return (!empty ($tst)) ? $lok : “”;
}

$plan_nr = (empty($_GET[‘plan_nr’])) ? $aptNo : $_GET[‘plan_nr’];
$year = (empty($_GET[‘year’])) ? date(“Y”, time()) : $_GET[‘year’];
$month = (empty($_GET[‘month’])) ? date(“m”, time()) : $_GET[‘month’];

$error = false; $alloc_year = array();
$query = "SELECT * FROM $main_table_name WHERE plan_nr = ‘$plan_nr’ AND YEAR(alloc) = ‘$year’ ";
if ($result = mysql_query($query)) {
while ($row = mysql_fetch_array ($result)){
$alloc_year[] = $row[“alloc”];
}
}

asort($alloc_year);

if (!empty ($_POST[‘submit’])){
$alloc = $_POST[‘alloc’];
if (!is_array($alloc)) $alloc = array();

foreach ($alloc AS $insert_value){
if (!in_array($insert_value, $alloc_year)){

  $query = "INSERT INTO $main_table_name SET plan_nr = '$plan_nr', alloc = '$insert_value'";
  if (!mysql_query($query) && !$error) {
    $error = true;
    die ("Database error: INSERT could not be accomplished. Line: ".__LINE__);
  }
}

}

foreach ($alloc_year AS $delete_value){
if (!in_array($delete_value, $alloc)){

  $query = "DELETE FROM $main_table_name WHERE alloc = '$delete_value' AND plan_nr = $plan_nr LIMIT 1";
  if (!mysql_query($query) && !$error) {
    $error = true;
    die ("Database error: DELETE could not be accomplished. Line: ".__LINE__);
  }
}

}

$error = false; $alloc_year = array();
$query = "SELECT * FROM $main_table_name WHERE plan_nr = ‘$plan_nr’ AND YEAR(alloc) = ‘$year’ ";
if ($result = mysql_query($query)) {
while ($row = mysql_fetch_array ($result)){
$alloc_year[] = $row[“alloc”];
}
}

$query = “SELECT plan_nr FROM $times_table_name WHERE plan_nr = $plan_nr”;
$num_rows = mysql_num_rows(mysql_query($query));
if ($num_rows > 0){
$query = “UPDATE $times_table_name SET last_mod = “.time().” WHERE plan_nr = $plan_nr”;
}else {
$query = “INSERT INTO $times_table_name SET last_mod = “.time().”, plan_nr = $plan_nr”;
}
if (!mysql_query($query) && !$error) {
die ("Database error: “.(($num_rows > 0) ? “Update” : “Insert”).” could not be accomplished. Line: ".LINE);
}
}

$query = “SELECT last_mod FROM $times_table_name WHERE plan_nr = $plan_nr”;
if ($result = mysql_query($query)){
while ($row = mysql_fetch_array ($result)){
$last_mod = get_time($row[“last_mod”]);
}
}
if (empty($last_mod)) $last_mod = “Not available”;
[/php]

This is the error message I am now getting

Parse error: parse error, unexpected ‘=’, expecting T_VARIABLE or ‘$’ in /data/members/paid/s/u/******.com/htdocs/******/users/ListCfg/.php on line 2

have a look at ListCfg/.php.
are there any php synax errors in there?

Tgis is the code that writes the config file

[php]
if($_POST[‘aptNo’]) $aptNo = ($_POST[‘aptNo’]);
if($_POST[‘shrtDesc’]) $shrtDesc = ($_POST[‘shrtDesc’]);
if($_POST[‘longDesc’]) $longDesc = ($_POST[‘longDesc’]);
if($_POST[‘selElevation’]) $selElevation = ($_POST[‘selElevation’]);
if($_POST[‘selBedrooms’]) $selBedrooms = ($_POST[‘selBedrooms’]);
if($_POST[‘bedNotes’]) $bedNotes = ($_POST[‘bedNotes’]);
if($_POST[‘Oven’]) $Oven = ($_POST[‘Oven’]);
if($_POST[‘Hob’]) $Hob = ($_POST[‘Hob’]);
if($_POST[‘Cooker’]) $Cooker = ($_POST[‘Cooker’]);
if($_POST[‘Microwave’]) $Microwave = ($_POST[‘Microwave’]);
if($_POST[‘Fridge’]) $Fridge = ($_POST[‘Fridge’]);
if($_POST[‘Washer’]) $Washer = ($_POST[‘Washer’]);
if($_POST[‘kitchNotes’]) $kitchNotes = ($_POST[‘kitchNotes’]);
if($_POST[‘TV’]) $TV = ($_POST[‘TV’]);
if($_POST[‘DVD’]) $DVD = ($_POST[‘DVD’]);
if($_POST[‘CDSystem’]) $CDSystem = ($_POST[‘CDSystem’]);
if($_POST[‘Games’]) $Games = ($_POST[‘Games’]);
if($_POST[‘Iron’]) $Iron = ($_POST[‘Iron’]);
if($_POST[‘Ironing’]) $Ironing = ($_POST[‘Ironing’]);
if($_POST[‘HairDryer’]) $HairDryer = ($_POST[‘HairDryer’]);

$fp = fopen (“ListCfg/$aptRef.php”, “w”);

$str = “<” . "?
$aptNo = “$aptNo”;
$shrtDesc = “$shrtDesc”;
$longDesc = “$longDesc”;
$selElevation = “$selElevation”;
$selBedrooms = “$selBedrooms”;
$bedNotes = “$bedNotes”;
$Oven = “$Oven”;
$Hob = “$Hob”;
$Cooker = “$Cooker”;
$Microwave = “$Microwave”;
$Fridge = “$Fridge”;
$Washer = “$Washer”;
$kitchNotes = “$kitchNotes”;
$TV = “$TV”;
$DVD = “$DVD”;
$CDSystem = “$CDSystem”;
$Games = “$Games”;
$Iron = “$Iron”;
$Ironing = “$Ironing”;
$HairDryer = “$HairDryer”;

?".">";

fwrite($fp, $str, strlen($str));
$aptDir = $row_aptDetails[‘aptRef’];
[/php]

Can’t be anything wrong with this because its already been read once

I think the problem is that when i click the next year link

[php]

Year: "> <?=$year+1?> [/php]

Its only pulling data from the one table, I need it pulling data from 2 tables if thats possible.

Anyone have an idea how this can be done!!!

i don’t think there is a prob with the file witing it, but with the file being written

maybe it’s a problem with the short php tags.
but i never used them.

try to replace $str = "<" . "? with $str = "<" . "?php

I have compromised on the designed for now. I’ve placed a form in the body tags and opened the calendar in a differant window, Seems to be working OK

Sponsor our Newsletter | Privacy Policy | Terms of Service