Jump to content

Welcome Page Shows But Not HTML


phprocker

Recommended Posts

I'm a bit stumped here and as usual I'm sure it's something simple.

 

I have an object that checks if a user is an admin. It works fine. But it the HTML below it is not getting displayed.

 

Take a look.

 

welcome.php

session_start();

$user = new users();

if (!isset($_SESSION['username'], $_SESSION['imadmin']) || $user->is_admin($_SESSION['username'])==0)
{
header('Location: index.php');
}

 

welcome.php is getting displayed without getting redirected to the index. But there's no HTML, just the URL to welcome.php in the bar.

 

Anyone?

 

Cheers!

Link to comment
https://forums.phpfreaks.com/topic/217280-welcome-page-shows-but-not-html/
Share on other sites

So there's nothing there when you do a View Source?

 

No.

I thought it was because I wasn't including the classes.php file but I added that and still same thing.

 

I have to get to sleep, thanks for looking. I'll try again in the morning and post the rest of the code when I can take a look at it through non-bloodshot eyes.  :D

 

Cheers people thanks!

I'll guess a fatal parse or fatal runtime error, due to something in the code that was not posted.

 

Are you doing this on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that all the php errors that your code produces would be reported and displayed? You will save a ton of time.

Ya I had errors off which was extremely stupid. I turned it off for another project.

 

Anyway, here's the error.

 

error on welcome.php

Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\site\classes.php on line 24

 

Code:

classes.php

class users
{
function is_admin($username)
{
	global $mysqli;
	$result = $mysqli->query("SELECT isadmin FROM users WHERE username = '$username'");
	$value = $result->fetch_object();

	if ($value->isadmin == 1) 
	{ 
		return 1;
	}
	return 0;
}
}

 

welcome.php

<?php 
session_start();

include 'root.php';
include ROOT.DS.'classes.php';

$user = new users();

if (!isset($_SESSION['username'], $_SESSION['imadmin']) || $user->is_admin($_SESSION['username'])==0)
{
header('Location: index.php');
}
?>

//the rest is all html

Fatal error: Call to a member function query() on a non-object in C:\xampp\htdocs\site\classes.php on line 24

 

The function query() is being called, but on a non-object, mysqli.

 

Where do you set mysqli, and is it declared global outside of the users class?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.