Trying to display user content in a profile page

I deleted the ; but still getting the error.

I can only guess without seeing the code.

home.php

session_start();

require './template_class.php';

$template= new Template();

$template->set_layout('homepage.tpl');

$template->set_title('Home');

$template->set_header('header.tpl');

$template->set_subtitle('Welcome to our site');


$visib='';
$disp='';

if(isset($_SESSION['useri']))
{
	$userid = $_SESSION['useri'];
}

if($userid && isset($visib) && isset($disp))
{
	$visib='visible';
	$disp='invisible';
}
else
{
	$visib='invisible';
	$disp='visible';
}

$template->add_content('home.tpl',array(
			                'visibility' => $visib,
				        'display' => $disp,
					));

if($userid)
{
$template->add_content2('home2.tpl',array(
					  'id' => $userid,
					  ));
}

$template->show();

And this errors appear when no user is login

( ! ) Notice: Undefined variable: userid in C:\net\www\users\home.php on line *26*
Call Stack
# Time Memory Function Location
1 0.0001 401920 {main}( ) ...\home.php **:** 0

( ! ) Notice: Undefined variable: userid in C:\net\www\users\home.php on line *42*
Call Stack
# Time Memory Function Location
1 0.0001 401920 {main}( ) ...\home.php **:** 0

OK, but that’s not the same error - “undefined variable: userid” is different to “undefined index: useri”.

Now I think the issue is that you’re checking its value in this line:

if($userid && isset($visib) && isset($disp))

but if the user is logged in, it will not exist at all. The easy way is to just add

$userid="";

just before you do the isset() check, presuming that the rest of your code will deal with it.

You should look at the logic in that line though. $visib and $disp are always going to exist, because you create them in the lines immediately before that statement. So there’s no real point checking that, and instead you should perhaps check to see whether $userid is empty or has a value in it. Or move that logic inside the bit of code that assigns the value to $userid in the first place. But if you do that, don’t forget to handle the situation where the session variable is not set.

1 Like

I put the $userid=''; and now there is no error even if no user is logged in.
Thank you for your help.

1 Like

Need a little help.
After you register and press submit you are send to this page:

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Redirect</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta http-equiv="Refresh" content="2;url=../home.php">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js"></script>
</head>

<body>

<div class="container h-100">
    <div class="row d-flex justify-content-center">
        <div class="col-6 mx-auto">
            <div class="jumbotron">
                <h5 class="display-5">User have been created</h5>
                <p class="lead">Thank you for making an account to our site.</p>
            </div>
        </div>
    </div>
</div>

</body>
</html>

The text is align like this:

But i want my text to be align in the center of the page like this(edited in paint):

What exactly do i have to change in the code to make it like that.

Best to ask in the CSS or HTML sections - page layout hasn’t really got anything to do with PHP.

2 Likes

Ok, thank you.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.