Jump to content

Passing a variable in the redirect statement


BelowZero

Recommended Posts

I want to display some specific data from my database (just data from a given date).

I first created a page where the user picks the date. After the date is defined it is passed to the next page where the data from that date is displayed. That page includes a form where users can edit the data. The form data is then passed to a third page for processing. All of this works fine. Now I want the user to be taken back to the previous page with the assigned date.

On the processing page I am using this statement:

header("Location: /teetimes/adminteetimes.php?teetimedate=$dateID");

and on the display page I'm using

$dateID = $_REQUEST[teetimedate];

The display page is using a SELECT...WHERE Date='$dateID' statement and $dateID is defined in the processing page.

Problem is: I'm redirected from the processing page back to the display page but the date isn't passed, so the correct data isn't being displayed.

Can anyone help me pass a variable using a header?? Or show me where my logic is lacking??

Thanks!

Link to comment
Share on other sites

You likely have some code in adminteetimes.php that is clearing the value, rather than comparing the value. You would need to post enough of your code (from both pages) that reproduces the problem for anyone here to directly help. You might also have a redirect in adminteetimes.php that could be causing this or you might have some url rewriting that could be causing this (do any $_GET values work?)

 

@l0gic, while it is true that the associative array index names are most often strings and should be quoted, php code works without quotes (produces a nasty error concerning an undefined constant and an assumption by php that you meant to put quotes around the name.)

Link to comment
Share on other sites

Thanks for the reply.

 

Here is the complete code for the display/form page:

<FORM Method = "POST" action ="update_tee_times.php">

<?php

include("opendatabase.php"); 

//$dateID = $_POST[teetimedate];
$dateID = $_REQUEST[teetimedate];
echo $dateID;
$closetime = "15:30:00";
$opentime = "17:30:00";

$result = mysql_query("
SELECT Date, Player1,Player2,Player3,Player4,Player5,Time, IF( TIME(Time) 
BETWEEN '$closetime' AND '$opentime','FFFF66','FFFFFF') AS 
color,Men,Women,Guest
FROM Daysheets
WHERE Date ='$dateID'"); 

echo "<h1>";
echo date("l: F d, Y", strtotime($dateID));
echo "</h1>";
echo "<table align=center width=700 border=1>\n";

echo "<th>Time</th><th>Player 1</th><th>C</th><th>Player 2</th><th>C</th><th>Player 3</th><th>C</th><th>Player 4</th><th>C</th><th>Player 5</th><th>C</th><th>M</th><th>W</th><th>G</th><th>Clear</th>";

$i=0;

while($row = mysql_fetch_array( $result )) 
{
$dateID = $row['Date'];
$timeID = $row['Time'];

echo "<tr>";
echo "<td>";

echo date("g:i ", strtotime($row[Time]));
echo "</td><td>"; 
echo "<input type='text' size='16' value= '$row[Player1]' name='player1[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>"; 
echo "<input type='text' size='1' value= '$row[C1]' name='c1[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>";
echo "<input type='text' size='16' value= '$row[Player2]' name='player2[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>"; 
echo "<input type='text' size='1' value= '$row[C2]' name='c2[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>";
echo "<input type='text' size='16' value= '$row[Player3]' name='player3[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>"; 
echo "<input type='text' size='1' value= '$row[C3]' name='c3[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>";
echo "<input type='text' size='16' value= '$row[Player4]' name='player4[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>"; 
echo "<input type='text' size='1' value= '$row[C4]' name='c4[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>";
echo "<input type='text' size='16' value= '$row[Player5]' name='player5[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>"; 
echo "<input type='text' size='1' value= '$row[C5]' name='c5[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>";
echo "<input type='text' size='1' value= '$row[Men]' name='men[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>";
echo "<input type='text' size='1' value= '$row[Women]' name='women[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>";
echo "<input type='text' size='1' value= '$row[Guest]' name='guests[$i]'
style ='font-size: 11px;  background-color:#{$row['color']};'>";
echo "</td><td>";
echo "<input type='checkbox' name='time1[$i]' value='$timeID'>";

echo "<input type='hidden' name='date[$i]' value='$dateID'>";
echo "<input type='hidden' name='time2[$i]' value='$timeID'>";
echo "</td></tr>";
$i++;
}

echo "</table>";

mysql_close($con);

?>
<br /><br /> 

<input type="Submit" name="Submit" value="Update Tee Times">
</FORM>

 

And for the processing page:


<?php	

header("Location: /teetimes/adminteetimes.php?teetimedate=$dateID");

include("opendatabase.php");

$size = count($_POST['player1']);

$i=0;

while ($i < $size)
     {
     $dateID = $_POST['date'][$i];
     $timeID1 = $_POST['time1'][$i];
     $timeID2 = $_POST['time2'][$i];
     $player1 = ($_POST['player1'][$i]);
     $player2 = ($_POST['player2'][$i]);
     $player3 = ($_POST['player3'][$i]);
     $player4 = ($_POST['player4'][$i]);
     $player5 = ($_POST['player5'][$i]);
     $men = ($_POST['men'][$i]);
     $women = ($_POST['women'][$i]);
     $guest = ($_POST['guests'][$i]);

     if (empty($timeID1))
     {
mysql_query("
UPDATE Daysheets
SET 
        Player1='$player1',
        Player2='$player2',
        Player3='$player3',
        Player4='$player4',
        Player5='$player5',
        Men='$men',
        Women='$women',
        Guest='$guest'

WHERE Date ='$dateID' 
AND Time ='$timeID2' ");
     $i++;
     }
     else
     {
     	mysql_query("
UPDATE Daysheets
SET 
        Player1='',
        Player2='',
        Player3='',
        Player4='',
        Player5='',
        Men='0',
        Women='0',
        Guest='0'

WHERE Date ='$dateID' 
AND Time ='$timeID2' ");
     $i++;
     }
     }

mysql_close($con)

?>

Thanks for your help.

Link to comment
Share on other sites

And for the processing page:...

 

You are executing the header() redirect as the first thing in the file. $dateID does NOT have any value in it at that time because you are not assigning a value to $dateID until about line 13 in that code.

Link to comment
Share on other sites

As I understand it, the header("Location...) has to be the first line

 

No it doesn't.

 

The only restriction is that it needs to occur before you send any output to the browser. However, if you are going to redirect, there's no point in sending any output to the browser since A) any output wouldn't be seen, even if it did work, and B) producing and sending any output would waste processor resources and bandwidth, even if it did work.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.