Session Variables - Error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Dear List -

Thanks for your help.

Here is another one.....

I cannot get my session variables to work. The program will print out a chess board and show the positions of the pieces after the move

Here are code snippets: The program is chess2.php


<?php  session_start();
error_reporting(1);
if (!isset($_SESSION['results'])){ //this always returns as not set.
print_r($_SESSION);
echo "starting";
$results = array(array("Br", "Bn", "Bb", "Bq", "Bk", "Bb", "Bn", "Br"),array("Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp", "Bp"), array("", "", "", "", "", "", "", ""),array("", "", "", "", "", "", "", ""),array("", "", "", "", "", "", "", ""), array("", "", "", "", "", "", "", ""),array("Wp", "Wp", "Wp", "Wp", "Wp", "Wp", "Wp", "Wp"), array("Wr", "Wn", "Wb", "Wq", "Wk", "Wb", "Wn", "Wr"));

$_SESSION['results'] = $results;
print_r($_SESSION);
}
else
{
         $results = $_SESSION['results'];
         echo "<br />starting values<br />";
         print_r($results);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
<html xmlns="http://www.w3.org/1999/xhtml";>
<body>
.
.
.
.
.
                <form method="post" action="chess2.php">
Move From<input type="text" name="move_from"></input><br /><br /> Move To <input type="text" name="move_to"></input><br /><br />
                <input type="submit" value="Enter Move"></input>
                </form>


<?php
print_r($_POST);

$from_before = '$'. $_POST[move_from];
echo"<br />";
echo "from_before = "; print_r($from_before);
echo"<br />";
$to = '$'. $_POST[move_to];
echo "to = $to";
//$to = $from;
$from = '' ;
echo"<br />";
echo "from after = $from";
echo"<br />";
echo "to after = $to";

$board = array //Correlation of input array [chessboard] with internal array [results]
(
                a8 => $results[0][0],
                b8 => $results[0][1],
                c8 => $results[0][2],
                d8 => $results[0][3],
                e8 => $results[0][4],
                f8 => $results[0][5],
                .
                .
                .
                .
                f1 => $results[7][5],
                g1 => $results[7][6],
                h1 => $results[7][7],
        );
                for($i = 0; $i <8; $i++) //  I get the correct results here
                {
for ($j = 0; $j < 8; $j++)
                        printf("%s ", $results[$i][$j]);
                        printf("<br />");
                }
                $_SESSION['results'] = $results;

</body></html>

Ethan


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux