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 6199265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T04:09:31+00:00 2026-05-24T04:09:31+00:00

I am a beginner to PHP and i want to make a static method

  • 0

I am a beginner to PHP and i want to make a static method that if its argument is empty it’ll show the message. If not, it’ll set the given message to a static variable for later use. But when i call the method to set the message, and then call it in another page to show the message. Nothing appear.

Here’s my portion of code for this “session.php” :

   class Session {

            public static $message; 


            public static function notify($message = ""){
                if(!empty($message)){
                    self::$message = $message;                    
                } else {                        
                    return self::$message;
                }
            }
}

    $session = new Session();

“add_user.php” :

<?php       
    require_once '../helper/session.php';       
?>

<?php
    if (isset($_POST["submit"])) {        

        $user->username = $_POST["username"];
        $user->password = $_POST["password"];
        $user->first_name = $_POST["first_name"];
        $user->last_name = $_POST["last_name"];
        if($result = $user->add_user()){
            Session::notify("New user added");
            redirect_to("../view/login.php");
        } else { Session::notify("Cannot add new user"); }

    }
?>

“login.php” :

<?php 
    require_once "../control/add_user.php";
?>

<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
        <link rel="stylesheet" href="../stylesheet/login.css" />
        <title>Welcome to Harmony</title>
    </head>

    <body>
        <header>
            <h2>Harmony</h2>
        </header>

        <section>
            <div id="formStyle">
                <h3>Login or Signup:</h3>
                <form action="login.php" method="post">

                    <p><label for="username">Username: </label>
                        <input type="text" name="username" value="" placeholder="Username"/></p>

                    <p><label for="password">Password: </label>
                        <input type="text" name="password" value="" placeholder="Password"/></p>

                    <input type="submit" name="submit" value="Submit" />
                    <input type="button" name="sign_up" value="Sign up" onClick="parent.location='add_user.php'">
                </form>
                            <?php echo Session::notify();  ?>
            </div>
        </section>
    </body>
</html>
  • 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-05-24T04:09:32+00:00Added an answer on May 24, 2026 at 4:09 am

    You aren’t really writing to the session, now are you?
    You should create two more methods for getting and setting the variables in the actual session. After the redirect, your message dissapears, because it is only saved on script execution.

    function set_notification($message) {
    $_SESSION['notification'] = $message; }
    function get_notification() {
    if(!empty($_SESSION['notification'])) {
    return $_SESSION['notification']; }
    

    Something like that 🙂

    Of course, for sessions to work, you should do a session_start() call in the beginning of the script. read more about them here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not a beginner at C# but I really need to increase my understanding,
I'm trying to add a set of dummy options to my dropdown to make
I just want to build my first dynamic Website. I want to use PHP,
i am a beginner in PHP.I have this query in my code. $qsq =
I am fairly a beginner with javascript. What I want to do is when
I'm a beginner to CSS, and i want to know the best technique to
Please forgive the extreme-beginner style of coding. I'm working with PHP and JSON strings
A beginner question, bear with me: I'm just wondering under what circumstances one should
A beginner's question. I'm building a .swf with Flex Ant. To my .swf I
What database should a beginner use in the C language? Can I use MySQL?

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.