Jump to content

[SOLVED] Call to a member function....on a non-object


Akenatehm

Recommended Posts

Hey Guys,

 

A bit of a problem here with a small Membership Class that I am working on.

 

Here's the error:

Fatal error: Call to a member function checkEmail() on a non-object in /Library/WebServer/Documents/projects/sample/register.php on line 78

 

Here's Member.class.php:

<?php

class Register{
private $dbhost,$dbuser,$dbpass,$database,$LastResult;
public function __construct($dbhost,$dbuser,$dbpass,$database) {
       $this->dbhost = $dbhost;
        $this->dbuser = $dbuser;
        $this->dbpass = $dbpass;
        $this->database = $database;
   	}
public function checkUsername($username){
	$this->username = mysql_escape_string($username);
	$connect = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass) or die(mysql_error());
	mysql_select_db($this->database) or die(mysql_error());	
	$checkuser= mysql_query("SELECT * FROM users WHERE Username = '$this->username'") or die(mysql_error());
	if(mysql_num_rows($checkuser) == 1){
		$response = "Username Already Exists <br />";
	}

mysql_close($connect);
}

public function samePasswords($password,$confirmpassword){
	$this->password = md5(mysql_escape_string($password));
	$this->confirmpassword = md5(mysql_escape_string($confirmpassword));
	if($this->password != $this->confirmpassword){
	$response = "Passwords Do Not Match<br />";	
	}	

	}

public function checkEmail($email)
	{
    	$formatTest = '/^[-\w+]+(\.[-\w+]+)*@[-a-z\d]{2,}(\.[-a-z\d]{2,})*\.[a-z]{2,6}$/i';
    	$lengthTest = '/^(.{1,64})@(.{4,255})$/';

    	$check = (preg_match($formatTest, $email) && preg_match($lengthTest, $email));
    	
    	if($check == 'false'){
    		$response = "Invalid Email<br />";
    	}
    
}      


public function createUser($username,$password,$email){
$connect = mysql_connect($this->dbhost,$this->dbuser,$this->dbpass) or die(mysql_error());
mysql_select_db($this->database) or die(mysql_error());	
$insertuser = mysql_query("INSERT into users (username,password,email) values('$username','$password','$email')") or die(mysql_error());
if($insertuser){
    	$response = "<p>Your account was successfully created. Please <a href=\"index.php\">click here to login</a>.</p>";
}

elseif(!$insertuser){
        $response = "Problem Creating User. Please Try Again Later.<br />";
}
mysql_close($connect);	


}



}
?>

 

and here is register.php:

<?php
session_start();
require "Connection.class.php";
require 'Member.class.php';
$select = new Connection('localhost','root','');
$select->db ('TimelessVoice');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">  
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
<title>User Management System (Tom Cameron for NetTuts)</title>
<link rel="stylesheet" type="text/css" media="screen" href="css/screen.css" />
<script src="jquery.js" type="text/javascript"></script>
<script src="validate/cmxforms.js" type="text/javascript"></script>
<script type="text/javascript" src="validate/jquery.validate.js"></script>
<script type="text/javascript">
$().ready(function() {
// validate signup form on keyup and submit
$("#registerform").validate({
	rules: {
		username: {
			required: true,
			minlength: 5
		},
		password: {
			required: true,
			minlength: 5
		},
		confirmpassword: {
			required: true,
			minlength: 5,
			equalTo: "#password"
		},
		email: {
			required: true,
			email: true
		},

	messages: {
		username: {
			required: "Please enter a username",
			minlength: "Your username must consist of at least 5 characters"
		},
		password: {
			required: "Please provide a password",
			minlength: "Your password must be at least 5 characters long"
		},
		confirm_password: {
			required: "Please provide a password",
			minlength: "Your password must be at least 5 characters long",
			equalTo: "Please enter the same password as above"
		},
		email: "Please enter a valid email address"
	}
	}		
});
	});
// check if confirm password is still valid after password changed
$("#password").blur(function() {
	$("#confirmpassword").valid();


	});

</script> 
</head>  
<body>  
<div id="main">
<?php

if(!empty($_POST['username']) && !empty($_POST['password']))
{
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = '';
    $database = 'TimelessVoice';

if(!$servervalidation->checkEmail($_POST['email']))
{
echo "<h1>Error</h1>";
    echo $servervalidation->checkEmail->$response;
}
elseif(!$servervalidation->checkUsername($_POST['username']))
{
echo "<h1>Error</h1>";
    echo $servervalidation->checkUsername->$response;
}
elseif(!$servervalidation->samePasswords($_POST['password'],$_POST['confirmpassword']))
{
echo "<h1>Error</h1>";
    echo $servervalidation->samePasswords->$response;
}
elseif(!$servervalidation->checkEmail($_POST['email'])){
echo "<h1>Error</h1>";
    echo $servervalidation->checkEmail->$response;	
}
else{
$servervalidation->createUser($servervalidation->username,$servervalidation->password,$servervalidation->email);
echo $servervalidation->$response;
}

}

else{
?>
    
   <h1>Register</h1>
    
   <p>Please enter your details below to register.</p>
    
<form method="post" action="register.php" name="registerform" id="registerform" class="cmxform">
<fieldset>
	<label for="username">Username:</label><input type="text" name="username" id="username" /><br />
	<label for="password">Password:</label><input type="password" name="password" id="password" /><br />
	<label for="confirmpassword">Confirm Password:</label><input type="password" name="confirmpassword" id="confirmpassword" /><br />
        <label for="email">Email Address:</label><input type="text" name="email" id="email" /><br />
	<input type="submit" name="register" id="register" value="Register" />
</fieldset>
</form>
    
   <?php
}
?>
</div>
</body>
</html>

 

Help would be greatly appreciated as I am new to OOP with PHP.

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.