php表单和会话分配在同一个文件中

I am trying to use post in a form to save form data from a dropdown as a session in the same file as the form

<?php
session_start();
if(isset($_SESSION['post-data']['surnameid']))
  unset($_SESSION['post-data']['surnameid']);
?>     

Then in the body of html

<form action="" method="post">
<?php
include 'connect.inc';

$sql = "SELECT surnameid FROM customer";
$result = mysql_query($sql);

echo "<select name='surnameid'>";
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['surnameid'] . "'>" . $row['surnameid'] .    </option>";
}
include 'close.inc';
?>

<br/> 
<input type="submit" name="Submit" value="Submit!" />
</form>
<?php    
$_SESSION['post-data'] = $_POST;

echo $_SESSION['post-data']['surnameid'];
?>

The assiginment to $_SESSION does not work

Try this : You forgot a double quote when you are putting echoing

make sure that you have the rows in the database ( we can't test that ) but i tested with predefined data and this version works

form.php

    <?php
session_start();

?>
<form action="" method="post">
<?php

echo "<select name='surnameid'>";
    echo "<option value='1'>test</option>";
    echo "<option value='2'>test2</option>";

?>

<br/> 
<input type="submit" name="Submit" value="Submit!" />
</form>
<?php    

if( !empty($_POST)){
    $_SESSION['post-data'] = $_POST;
}


if(isset($_SESSION['post-data']['surnameid']))
echo $_SESSION['post-data']['surnameid'];
?>

test_session.php

<?php
session_start();
print_r($_SESSION['post-data']['surnameid']);

?>