Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7942831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T00:05:28+00:00 2026-06-04T00:05:28+00:00

I’m continuing to write a maze generator to teach myself php… I’ve set up

  • 0

I’m continuing to write a maze generator to teach myself php…

I’ve set up a session, and a form to collect a name and a maze size (5-20).

On the first run, that works fine, the maze is generated.

What I would like for further sessions is that the name is remembered, but the size is re-input.

I’ve tried using another (different) form if the session is not new, but it’s not recognising/running it, and errors, telling me that $mazesize is an unrecognised index.

Code:

<?php
session_start();
error_reporting(-1);
?>
<html>
<head>
</head>
<body>
<?php

include 'ClassFunc1.php';

//program functionality
if (!isset($_SESSION['name']) && !isset($_POST['name'])){
    //if no data, print form
        ?><table><tr>
        <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
        <td>Name: </td><td><input type="text" name="name"></td></tr>
        <tr><td>Maze size (min 5 max 20): </td><td><input type="text" name="mazesize"></td></tr>
        <tr><td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td></tr>
        </form></table>
        <?php
}else if (!isset($_SESSION['name']) && isset($_POST['name']) && isset($_POST['mazesize'])){
        //if a session doesn't exist but the form has been submitted
        //check to see if the form has all required values
        //create a new session
        if(!empty($_POST['name'])){
        $_SESSION['name']=$_POST['name'];
        $_SESSION['start']=time();
        echo "Welcome, ".$_POST['name'].". A new session has been activated for you. Click <a href=".$_SERVER['PHP_SELF'].">here</a> to refresh the page.";
        if($_POST['mazesize']>20){
            $m_size=20;
        }elseif($_POST['mazesize']<5){
            $m_size=5;
        }else{
            $m_size=$_POST['mazesize'];
        }
        define("COL_MAX",$m_size);
        define("ROW_MAX",$m_size);
        run_maze($_POST['name']);
        close_down();
        }else{
            echo "ERROR. Please enter your name and a maze size";
        }
}else if (isset($_SESSION['name'])) {
        //if a previous session exists
        //calculate elapsed time since session start and now
        echo "Welcome back, ".$_SESSION['name'].". This session was activated ".round((time()-$_SESSION['start'])/60)." minute(s) ago. Click <a href=".$_SERVER['PHP_SELF'].">here</a> to refresh the page.<br />";
        echo "Current session ID: ".session_id();
    //Ask for a new maze size
        ?><table><tr>
        <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
        <td>Maze size (min 5 max 20): </td><td><input type="text" name="mazesize"></td></tr>
        <tr><td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td></tr>
        </form></table>
        <?php
        if($_POST['mazesize']>20){
            $m_size=20;
        }elseif($_POST['mazesize']<5){
            $m_size=5;
        }else{
            $m_size=$_POST['mazesize'];
        }
    define("COL_MAX",$m_size);
    define("ROW_MAX",$m_size);
    run_maze($_POST['name']);
    close_down();
}

//session_destroy();


?>

The “include” file is the class, methods & functions.

I’m sure I’ve done something wrong, can anyone help?

Many thanks

ETA:

(code amended after the echo “ERROR… line)

    }else if (isset($_SESSION['name']) && !isset($_POST['n_mazesize'])) {
            //if a previous session exists but n_mazesize not set
            //calculate elapsed time since session start and now
            echo "Welcome back, ".$_SESSION['name'].". This session was activated ".round((time()-$_SESSION['start'])/60)." minute(s) ago. Click <a href=".$_SERVER['PHP_SELF'].">here</a> to refresh the page.<br />";
            echo "Current session ID: ".session_id();
        //Ask for a new maze size
            ?><table><tr>
            <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post">
            <td>Maze size (min 5 max 20): </td><td><input type="text" name="n_mazesize"></td></tr>
            <tr><td colspan="2" align="center"><input type="submit" name="submit" value="Submit"></td></tr>
            </form></table>
            <?php
    }else if (!isset($_SESSION['name']) && isset($_POST['n_mazesize'])){
            //if a previous session exists and n_mazesize is set
            //calculate elapsed time since session start and now
            echo "Welcome back, ".$_SESSION['name'].". This session was activated ".round((time()-$_SESSION['start'])/60)." minute(s) ago. Click <a href=".$_SERVER['PHP_SELF'].">here</a> to refresh the page.<br />";
            echo "Current session ID: ".session_id();
            if(!empty($_POST['n_mazesize'])){
            if($_POST['n_mazesize']>20){
                $m_size=20;
            }elseif($_POST['n_mazesize']<5){
                $m_size=5;
            }else{
                $m_size=$_POST['n_mazesize'];
            }
        run_maze($_SESSION['name'], $m_size);
        close_down();
        }

    //session_destroy();
    }

    ?>
</body>
</html> 

This asks for the size but on submission returns a blank screen 🙁

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T00:05:29+00:00Added an answer on June 4, 2026 at 12:05 am

    The value of $_POST[‘mazesize’] is only available when the form is submitted. You should add a condition:

    if ($_SERVER['REQUEST_METHOD'] == 'POST') {
        // use posted data here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I'm trying to create an if statement in PHP that prevents a single post

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.