Jump to content
Killersites Forums

Colorbox Wont Show Up


PHoutenbos
 Share

Recommended Posts

I have a problem.
I have followed the video course and the full code adopted. (i'm not finished yet with the course)
I still do not have a login box and the colorbox does not seem to work.
i also get a syntax error with noconflict

below my code:

t_login.php

<Link href = "<php ​​echo APP_RESOURCES;?> Css / fp_style.css" media = "screen" rel = "stylesheet" type = "text / css" />

<script type="text/javascript" src="http://code.jquery.c...n.js"> </ script>
<script type="text/javascript"> $ noConflict (). </ script>

<Script type = "text / javascript" src = "<php ​​echo APP_RESOURCES;?> Javascript / colorbox / colorbox.js"> </ script>
<Link href = "<php ​​echo APP_RESOURCES;?> Javascript / colorbox / colorbox.css" media = "screen" rel = "stylesheet" type = "text / css" />

</ Script>

Login.php

<?php

include("init.php");

if (isset($_POST['submit']))
{
	// get data
	$FP->Template->setData('input_user', $_POST['username']);
	$FP->Template->setData('input_pass', $_POST['password']);
	
	// validate data
	if ($_POST['username'] == '' || $_POST['password'] == '')
	{
		// show error
		if ($_POST['username'] == '') { $FP->Template->setData('error_user', 'required field!'); }
		if ($_POST['password'] == '') { $FP->Template->setData('error_pass', 'required field!'); }
		$FP->Template->setAlert('Please fill in all required fields', 'error');
		$FP->Template->load(APP_PATH . "core/views/v_login.php");
	}
	else if ($FP->Auth->validateLogin($FP->Template->getData('input_user'), $FP->Template->getData('input_pass')) == FALSE)
	{
		// invalid login
		$FP->Template->setAlert('Invalid username or password!', 'error');
		$FP->Template->load(APP_PATH . "views/v_login.php");
	}
	else
	{
		// successful log in	
		$_SESSION['username'] = $FP->Template->getData('input_user');
		$_SESSION['loggedin'] = TRUE;
		$FP->Template->load(APP_PATH . "core/views/v_loggingin.php");
	}
}
else
{
	$FP->Template->load(APP_PATH . "core/views/v_login.php");
}

init.php:

<?php

/*
	INIT
	Basic configuration settings
*/

// create application settings
define("SITE_PATH","http://localhost/PassieCMS/"); //<- aanpassen
define ("APP_PATH", str_replace("\\","/",dirname(__FILE__)) . "/");

define("SITE_RESOURCES", "http://localhost/PassieCMS/resources/");
define("APP_RESOURCES", "http://localhost/PassieCMS/app/resources/");
define("SITE_CSS", "http://localhost/PassieCMS/resources/css/style.css"); //<-aanpassen indien andere template

// database settings
$server = 'localhost'; // database server/host
$user = 'root'; //gebruikersnaam database
$pass = 'root'; // wachtwoord database
$db = 'fp_cms'; // selecteert database

// error reporting
mysqli_report(MYSQLI_REPORT_ERROR);

// create FlightPath core object
require_once(APP_PATH . "core/core.php");
$FP = new FlightPath_Core($server, $user, $pass, $db);

Core.php

<?php

/* 	core FlightPath class
	Creates the central FlightPath object, as well as core functionality
*/
class FlightPath_Core
{
	public $Template, $Auth, $Database;
	
	function __construct($server, $user, $pass, $db)
	{
		//create database connection
		$this->Database = new mysqli($server, $user, $pass, $db);
		
		// create template object
		include(APP_PATH . "core/models/m_template.php");
		$this->Template = new Template();
		$this->Template->setAlertTypes(array('success', 'warning', 'error'));
		
		// create auth object
		include(APP_PATH . "core/models/m_auth.php");
		$this->Auth = new Auth();
		
		// start session
		session_start();
	}
	
	function __destruct()
	{
		$this->Database->close();
	}
	
	
	function head()
	{
		if ($this->Auth->checkLoginStatus())
		{
			include(APP_PATH . "core/templates/t_head.php");	
		}
		if (isset($_GET['login']) && $this->Auth->checkLoginStatus() == FALSE)
		{
			include(APP_PATH . "core/templates/t_login.php");	
		}	
	}
	
	function body_class()
	{
		if ($this->Auth->checkLoginStatus())
		{
			echo " fp_editing";	
		}	
	}
	
	function toolbar()
	{
		if ($this->Auth->checkLoginStatus())
		{
			include(APP_PATH . "core/templates/t_toolbar.php");	
		}	
	}
	
	function login_link()
	{
		if ($this->Auth->checkLoginStatus())
		{
			echo "<a href='" . SITE_PATH . "app/logout.php'>Logout</a>";
		}
		else
		{
			echo "<a href='?login'>Login</a>";	
		}	
	}
	
	
	
	
}

index.php

<?php include ("app/init.php");?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PassieCMS</title>
<link href="resources/css/style.css" rel="stylesheet" type="text/css">
<?php $FP->head();?>
</head>

<body class="home <?php $FP->body_class();?>">
	
    <?php $FP->toolbar();?>
    
    <div id="wrapper">
    	<h1>Website</h1>
        
        <div id="banner">
        	<img src="resources/images/banner.jpg" alt="banner" width="900" height="140">
        </div>
        
        <ul id="nav">
        	<li><a href="#">Home</a></li>
            <li><a href="#">Test link</a></li>
            <li><a href="#">Longer Text Link</a></li>
            <li><a href="#">Contact us</a></li>
        </ul>
        
        <div id="content">
        	<div class="left">
            	<h2>Header info...</h2>
                <p>Text here...</p>
            </div>
            <div class="right">
            	<p>Text here...</p>
                <p>Text here...</p>
            </div>
        </div>
        
        <div id="footer">
        	Copyright 2014 PassieCMS | <?php $FP->login_link();?>
        </div>
        
     </div>
      
</body>
</html>

M_auth:

<?php

/*
	Authorization Class
	Deal with auth tasks
*/

class Auth
{
	private $salt = '2pkhout';
	
	/*
		Constructor
	*/
	function __construct()
	{
	}
	
	/*
		Functions
	*/
	function validateLogin($user, $pass)
	{
		// access db
		global $Database;
		
		// create query
		if ($stmt = $Database->prepare("SELECT * FROM users WHERE username = ? AND password = ?"))
		{
			$stmt->bind_param("ss", $user, md5($pass . $this->salt));
			$stmt->execute();
			$stmt->store_result();
			
			// check for num rows
			if ($stmt->num_rows > 0)
			{
				// success
				$stmt->close();
				return TRUE;
			}
			else
			{
				// failure
				$stmt->close();
				return FALSE;
			}
		}
		else
		{
			die("ERROR: Could not prepare MySQLi statement.");
		}
	}
	
	function checkLoginStatus()
	{
		if (isset($_SESSION['loggedin']))
		{
			return TRUE;
		}
		else
		{
			return FALSE;
		}
	}
	
	function logout()
	{
		session_destroy();
		session_start();
	}
}

v_login

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>	
		<title>Log In</title>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<link href="views/style.css" media="screen" rel="stylesheet" type="text/css">
	</head>
	<body>
		<h1>Log In</h1>
		<div id="content">
		
			<form action="" method="post">
			<div>
			
				<?php
					$alerts = $this->getAlerts();
					if ($alerts != '') { echo '<ul class="alerts">' . $alerts . '</ul>'; }
				?>
				
				<div class="row">
					<label for="username">Username: *</label>
					<input type="text" name="username" value="<?php echo $this->getData('input_user'); ?>">
					<div class="error"><?php echo $this->getData('error_user'); ?></div>
				</div>
				<div class="row">
					<label for="password">Password: *</label>
					<input type="password" name="password" value="<?php echo $this->getData('input_pass'); ?>">
					<div class="error"><?php echo $this->getData('error_pass'); ?></div>
				</div>
			
				<div class="row">
					<p class="required">* required</p>
					
					<input type="submit" name="submit" class="submit" value="Submit">
				</div>

			</div>
			</form>
		
		</div>
	</body>
</html>

And also when i try to login i get the following error:

Fatal error: Call to a member function prepare() on a non-object in C:\xampp\htdocs\PassieCMS\app\core\models\m_auth.php on line 28

Does anyone know what the problem could be?

Link to comment
Share on other sites

I responded in your other topic about your Javascript issues. As for the "non-object" issue, that's usually due to incorrect database login info -- where your database username or password is incorrect. Make sure to double check that, and check the default mysql username for whatever program you are using to run MySQL (MAMP, WAMP, etc.)

Link to comment
Share on other sites

I responded in your other topic about your Javascript issues. As for the "non-object" issue, that's usually due to incorrect database login info -- where your database username or password is incorrect. Make sure to double check that, and check the default mysql username for whatever program you are using to run MySQL (MAMP, WAMP, etc.)

 

I use the program Xampp 
the problem seems to occur in the database syntax of rule 28. for 
once I insert the query in phpmyadmin to test the code, I get the following 
message 
 
SELECT * FROM users WHERE username =? AND password =? 
  LIMIT 0, 25 
MySQL reports: Documentation 
 
# 1064 - You have an error in your SQL syntax; check the manual That corresponds to your MySQL server version pounds for the right syntax to use near '? AND password =? 
LIMIT 0, 25 'at line 1
 
When i enter SELECT * FROM users WHERE username  AND password 
 
this is the result
 
MySQL returned an empty result set returned (0 rows). (Query took 0.0003 sec)
Link to comment
Share on other sites

You can't testing prepared statements in PHPMyAdmin -- you will get errors. That line is perfectly fine, valid SQL (well, it is if the "?" are properly filled in with the data.) Again, this usually comes down to an incorrect username and password. For XAMPP, I believe the username should be "root" and the password is blank ("").

Link to comment
Share on other sites

You can't testing prepared statements in PHPMyAdmin -- you will get errors. That line is perfectly fine, valid SQL (well, it is if the "?" are properly filled in with the data.) Again, this usually comes down to an incorrect username and password. For XAMPP, I believe the username should be "root" and the password is blank ("").

 

if i leave it blank this is the respons

 

 Warning: mysqli::mysqli(): (HY000/1045): Access denied for user 'root'@'localhost' (using password: NO) in C:\xampp\htdocs\PassieCMS\app\core\core.php on line 13

Warning: mysqli::close(): Couldn't fetch mysqli in C:\xampp\htdocs\PassieCMS\app\core\core.php on line 30

 

the password for my is also root. i logout in phpmyadmin and sign in again with username root en password root. 

Link to comment
Share on other sites

OK, leave the username/password alone then -- sounds like you have that part correct. 

 

I double checked, and for the validateLogin() method in m_auth.php, it seems like doesn't match up with my code, which is:

 

function validateLogin($user, $pass)
{
// access db
global $FP; 


// create query
if ($stmt = $FP->Database->prepare("SELECT * FROM users WHERE username = ? AND password = ?"))
See how there is a global $FP object that is accessed, that stores the database, authorization object, etc? Are you following my tutorial? Or are you building things on your own on top of it? I'm pretty sure I didn't demonstrate the code you are using in the validateLogin() method. Or maybe that code was left over from earlier in the course, when I was integrating the login, and either you missed editing it to add the $FP, or you haven't gotten there yet in the videos? I'm not sure.
Link to comment
Share on other sites

 

OK, leave the username/password alone then -- sounds like you have that part correct. 

 

I double checked, and for the validateLogin() method in m_auth.php, it seems like doesn't match up with my code, which is:

 

function validateLogin($user, $pass)
{
// access db
global $FP; 


// create query
if ($stmt = $FP->Database->prepare("SELECT * FROM users WHERE username = ? AND password = ?"))
See how there is a global $FP object that is accessed, that stores the database, authorization object, etc? Are you following my tutorial? Or are you building things on your own on top of it? I'm pretty sure I didn't demonstrate the code you are using in the validateLogin() method. Or maybe that code was left over from earlier in the course, when I was integrating the login, and either you missed editing it to add the $FP, or you haven't gotten there yet in the videos? I'm not sure.

 

 

This was the problem, it works well now! I had forgotten that piece suit. I am working on video 20 because I'm stuck there with colorbox but that is described in the other topic.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...