Php会话无法处理输入

I have this code that requires the user to type in a number and that number of lessons will be created.

<form action="k1levelselect.php" method="post"> How many lessons do you want to create?
<input type="text" name="number" value=""><br>
<input type="submit" value="Submit">
</form>

<?php
session_start();
$_SESSION['views']=$number;
?>

Then it will bring me to the next page and prints out the number of 'Lessons' the user wants.

 <?php
    session_start();

    $noOfLesson = $_SESSION['views'];
        for($i = 1; $i <= $noOfLesson; $i++) {
        echo "Pageviews=". $_SESSION['views'];
    echo "<div>
        <a href=\"k1levelX.php?lesson=".$i."\"><span>Lesson ".$i."</span></a>           
    </div>
    <br>";
        }
        ?>

The problem is in the first code, i am not able to bring the input 'number' over to the session using $_SESSION['views']=$number; However, it works when i hardcode a number like eg. $_SESSION['views']=4;

Foreword: (edit)
I noticed you've asked a few questions since first joining Stack but have not accepted any.

If there is a reason as to why you haven't accepted any, probably because none of the answers given solved an issue, do inform the person or persons to elaborate on their answer.


Answer:

Here, this is what you need to do, in regards to your comment about it "not working": (plus, you weren't assigning a variable in regards to your POST form element). This has already been explained.

Your (new) form: - Make sure there is nothing above this (no space, cookie, HTML, nothing), because it will cause/throw a "Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at..." error; if error reporting is ON by default.

<?php

session_start();

// check if session is set, which will echo the last entered number
if(isset($_SESSION['views'])){
echo $_SESSION['views'];
}

?>

<form action="k1levelselect.php" method="post">
How many lessons do you want to create?
<input type="text" name="number" value=""><br>
<input type="submit" value="Submit">
</form>

Copy this into your k1levelselect.php file: - Make sure there is nothing above this (no space, cookie, HTML, nothing), because it will cause/throw a "Warning: session_start(): Cannot send session cache limiter - headers already sent (output started at..." error; if error reporting is ON by default.

<?php 

session_start();
$number = $_POST['number']; // assign variable from POST
$_SESSION['views']=$number; // assign session to variable

    $noOfLesson = $_SESSION['views'];
        for($i = 1; $i <= $noOfLesson; $i++) {
        echo "Pageviews=". $_SESSION['views'];
    echo "<div>
        <a href=\"k1levelX.php?lesson=".$i."\"><span>Lesson ".$i."</span></a>           
    </div>
    <br>";
        }
?>

If error reporting is not ON by default, add the following below your opening <?php tags:

error_reporting(E_ALL);
ini_set('display_errors', 1);

It will show you any errors; if any.

You never assigned any value to $number which must first come from your named form element number. Assign a variable to the POST variable from your named form element, then use the session name and assign it to the $number variable.

session_start();
$number = $_POST['number'];
$_SESSION['views']=$number;