I am trying to get a searched date from one page to appear on another page, i have this code on one page so the user can search for a specific date:

<?php 

	if(!empty($_POST['searchdate'])) {
	$mydate = $_POST['searchdate'];
	} else {
	$mydate = date('Y-m-d');
	}

	$id = $_POST['id']; 
	if(empty($id) && !empty($_POST['ConveyorNumber'])) {
		$id = $_POST['ConveyorNumber'];
	}
	
	$Date=date ("Y-m-d H:i");
?>

<form action="baa_history3.php" method="post" name="history" id="history">
<div class="menu_date_history">
<input name="searchdate" type="text" id="searchdate" value="<?php echo $mydate; ?>" size="30"/>
<input name="date_history" type="submit" id="date_history" value="Search" size="30" />
<input name="id" type="hidden" value="<?php echo $id; ?>" /></div>
</form>

It appears fine on baa_history3.php, but then there is a button on this page to go to another form which i want to display this same date that was searched.

I have this code:

<?php

if($_POST["orderby"] == "ConveyorNumber"){
$orderby = "cn.ConveyorNumber";
} else {
$orderby = "`Date`";
} 

$location=$_POST['location'];
if(!empty($_SESSION["Shift"]))$Shift = $_SESSION["Shift"];
if(!empty($_SESSION["Site"]))$Site = $_SESSION["Site"];
   $thisdate = $_POST['thisdate']; 
   // print_r($_POST);

$start = $_POST['start'];
if(empty($start) or $start < 0) $start =0;
if(!empty($_POST['searchdate'])) {
$mydate = $_POST['searchdate'];
$query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' and date(cn.`Date`)='$mydate' and cn.Location = '$location' order by $orderby";
} else {
$query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' and cn.Location = '$location' order by $orderby";
}

$Asset = mysql_query($query_Asset, $Database_Connection) or die(mysql_error());


?>

<td colspan="9">SHIFT:<?php echo $Site . ' - ' .$Shift ; ?></td>
<input name="searchdate" type="hidden" id="searchdate" value="<?php echo $mydate; ?>" size="30"/>
<?php echo $mydate; ?>

The shift and site display fine, but the searched date doesnt, it is because the shift and site are using session?

yes you need to save the data if you want to display it on a further page

you will have to add to baa_history3.php something that saves the searched date to the session so you can then pull it back later in the $_SESSION and not $_POST.

$_POST will only work in the immediate page you have posted to

like this: $thisdate = if(!empty($_SESSION);

what about this part:

if(!empty($_POST)) {
$mydate = $_POST;

does this need to use session as well?

If it's not being used on the page immediately displayed when you "submit" the form then it would have to be yes. Don't forgot you will need to tell your scripts that everytime the form is submitted it should update the session values.

and like this: $thisdate = if(!empty($_SESSION); doesn't look right
try:

# check to see if a new searchdate has been posted
if (strlen($_POST['searchdate']) > 0)) {
    # if its been psoted then use the new date and update the session
    $thisdate = $_POST['searchdate'];
    $_SESSION['thisdate'] = $thisdate;
} else {
    # if no new date has been submitted then use the one in the session
    $thisdate = $_SESSION['thisdate']
}

where am i to enter this?

do i replace this: $thisdate = $_POST;

if you put my code at the top of your pages it will look for a new date being submitted on a form from previous page and if its not been changed it will pull the one from the session so everywhere in your current code everytime you want to look at the date just use $thisdate and remove all things that change it like $thisdate = $_POST;

there is really much better ways of doing this but this is a little starting point and will help you progress

right ok, entering your code in place of this line: $thisdate = $_POST;

and the page doesnt display anything....

change line 8 from
$thisdate = $_SESSION
to
$thisdate = $_SESSION;

my code looks like this and still the page wont display:

if(!empty($_SESSION["Shift"]))$Shift = $_SESSION["Shift"];
if(!empty($_SESSION["Site"]))$Site = $_SESSION["Site"];

# check to see if a new searchdate has been posted
if (strlen($_POST) > 0)) { # if its been psoted then use the new date and update the session
$thisdate = $_POST;
$_SESSION = $thisdate;} else { # if no new date has been submitted then use the one in the session
$thisdate = $_SESSION};
// print_r($_POST);
//print_r($_POST);

$start = $_POST;
if(empty($start) or $start < 0) $start =0;

if(!empty($_POST)) {
$mydate = $_POST;
$query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' and date(cn.`Date`)='$mydate' order by $orderby";
} else {
$query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' order by $orderby";
}

i have tried this line: $thisdate = $_SESSION}; like $thisdate = $_SESSION; but it still doesnt work.

i can see at least one syntax error. please post code wrapped inside the code tags

so we can talk about line numbers etc

you should go on php.net and lookup error reporting and turn all errors on and make them print to browser whilst you are doing development work and it will tell you what line of the code is breaking it

$thisdate = $_SESSION}; is wrong straight away, why do you have a } in there?

i have removed the }, i dont understand why its not needed tho, because you have 2 of { in your code which you dont close using }

my mistake the are closed.

here is my code:

1 <?php
2
3 session_start();
4 if(!isset($_SESSION) && !isset($_SESSION)) {
5 header("location:login2.php");
6 exit;
7 }
8
9 require_once('Connections/Database_Connection.php');
10
11 if($_POST["orderby"] == "ConveyorNumber"){
12 $orderby = "cn.ConveyorNumber";
13 } else {
14 $orderby = "`Date`";
15 }
16
17 $location=$_POST;
18 if(!empty($_SESSION["Shift"]))$Shift = $_SESSION["Shift"];
19 if(!empty($_SESSION["Site"]))$Site = $_SESSION["Site"];
20
21 # check to see if a new searchdate has been posted
22 if (strlen($_POST) > 0)) {
23 # if its been psoted then use the new date and update the session
24 $thisdate = $_POST;
25 $_SESSION = $thisdate;} else {
26 # if no new date has been submitted then use the one in the session
27 $thisdate = $_SESSION;
28 }
29
30 // print_r($_POST);
31
32
33
34 $query_Recordset2 = "SELECT distinct Location FROM t5_week3_shift3 where Site='".$Site."' and Shift='".$Shift."' order by Location";
35 $Recordset2 = mysql_query($query_Recordset2, $Database_Connection) or die(mysql_error());
36
37 $location_options = "";
38
39 while($row = mysql_fetch_assoc($Recordset2)) {
40 if(empty($location)) $location = $row;
41 $sel = '';
42 if($row == $location) $sel = 'selected="selected"';
43 $location_options .= '<option value="'.$row.'" '.$sel.'>'.$row.'</option>';
44 }
45
46
47 $start = $_POST;
48 if(empty($start) or $start < 0) $start =0;
49 // $query_Asset = "SELECT c.BAA_Shift, c.BagReference,a.Asset_ID, a.AssetType, a.Location FROM assets as a join t5_week3_shift3 as c on
a.Asset_ID = c.Asset_ID join conveyor_number as cn WHERE c.`Asset_ID` = '$id'and date(`Date`) = '$thisdate' limit 0,1";
50 // $query_Asset = "SELECT c.*,cn.*,a.Asset_ID, a.AssetType FROM assets as a join t5_week3_shift3 as c on a.Asset_ID = c.Asset_ID join conv
eyor_number as cn on c.Asset_ID WHERE c.`Asset_ID` = '$id' and date(cn.`Date`) = '$thisdate' limit 0,1";
51
52 if(!empty($_POST)) {
53 $mydate = $_POST;
54 $query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as
cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' and date(cn.`Date`)='$mydate' and cn.Location = '$location
;
55 } else {
56 $query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as
cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' and cn.Location = '$location' order by $orderby";
57 }
58
59 $Asset = mysql_query($query_Asset, $Database_Connection) or die(mysql_error());
60
61 ?>

22 if (strlen($_POST) > 0)) {
change to:
22 if (strlen($_POST) > 0) {

ok that worked.

now how do i get it to display within code like this:

<?php
echo'<table border=1 >
<tr>
<td colspan="20" align="center">SITE DATA SHEET</td>
<td colspan="8"><img src="images/logo.gif" width="171" height="88" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="6">DIR:</td>
<td>&nbsp;</td>
<td colspan="7">Surveyed By:</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td colspan="8">Date:<?php echo $thisdate; ?></td>
</tr>

as this doesnt work. it will work outside of this code.

Member Avatar for diafol

You are echoing within an echo. Try:

<td colspan="8">Date:' . $thisdate . '</td>...

thanks.

this code is making all records displays, but i only want to display records relating to $thisdate, what do i need to change?

$start = $_POST;
if(empty($start) or $start < 0) $start =0;

if(!empty($_POST)) {
$mydate = $_POST;
$query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' and date(cn.`Date`)='$mydate' order by $orderby";
} else {
$query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' order by $orderby";
}

$Asset = mysql_query($query_Asset, $Database_Connection) or die(mysql_error());

if i change $mydate to $thisdate, it still displays all records....

Member Avatar for diafol

Use code tags in your posts for a start. That's just horrible to try and read. :)

this code is making all records displays, but i only want to display records relating to $thisdate, what do i need to change?

9 require_once('Connections/Database_Connection.php');
10
11 if($_POST["orderby"] == "Location"){
12 $orderby = "cn.Location";
13 } else {
14 $orderby = "`Date`";
15 }
16
17 if(!empty($_SESSION["Shift"]))$Shift = $_SESSION["Shift"];
18 if(!empty($_SESSION["Site"]))$Site = $_SESSION["Site"];
19
20 # check to see if a new searchdate has been posted
21 if (strlen($_POST) > 0) { # if its been psoted then use the new date and update the session
22 $thisdate = $_POST;
23 $_SESSION = $thisdate;} else { # if no new date has been submitted then use the one in the session
24 $thisdate = $_SESSION;
25 }
26 // print_r($_POST);
27 //print_r($_POST);
28
29 $start = $_POST;
30 if(empty($start) or $start < 0) $start =0;
31
32 if(!empty($_POST)) {
33 $mydate = $_POST;
34 $query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as
cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' and date(cn.`Date`)='$mydate' order by $orderby";
35 } else {
36 $query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as
cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' order by $orderby";
37 }
38
39 $Asset = mysql_query($query_Asset, $Database_Connection) or die(mysql_error());
40
41
42 ?>

if i change $mydate to $thisdate, it still displays all records....

Member Avatar for diafol

?? Use [ CODE ] tags. Plain text code is too difficult (for me anyway).

what do you mean? this is my code straight from my page....

he means:When you edit your response press the the

ontop of the editbox

 
[code]

//  result looks like this
require_once('Connections/Database_Connection.php');

if($_POST["orderby"] == "Location"){
$orderby = "cn.Location";
} else {
$orderby = "`Date`";
} 

if(!empty($_SESSION["Shift"]))$Shift = $_SESSION["Shift"];
if(!empty($_SESSION["Site"]))$Site = $_SESSION["Site"];

# check to see if a new searchdate has been posted
if (strlen($_POST['searchdate']) > 0) {    # if its been psoted then use the new date and update the session    
$thisdate = $_POST['searchdate'];    
$_SESSION['thisdate'] = $thisdate;} else {    # if no new date has been submitted then use the one in the session   
$thisdate = $_SESSION['thisdate'];
}
   // print_r($_POST);
    //print_r($_POST);

$start = $_POST['start'];
if(empty($start) or $start < 0) $start =0;

if(!empty($_POST['searchdate'])) {
$mydate = $_POST['searchdate'];
$query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' and date(cn.`Date`)='$mydate' order by $orderby";
} else {
$query_Asset = "SELECT c.*,cn.*,c.BAA_Shift, c.BagReference,c.Asset_ID, c.AssetType FROM t5_week3_shift3 as c join conveyor_number as cn on c.Asset_ID = cn.ConveyorNumber WHERE c.`Shift` = '$Shift' and c.Site='$Site' order by $orderby";
}

$Asset = mysql_query($query_Asset, $Database_Connection) or die(mysql_error());


?>

Please use code tags. They make code easier to read.

i thought i had done this when i posted previous code? i used the code button.

Member Avatar for diafol

You did

ok, so can someone please help me....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.