Jump to content

Recommended Posts

Hi,

 

Could someone help me with this script I wrote please?

 

The problem is, if you submit data from a form to the page, everything works up to the point of elseif ($user->loadalias($_POST['alias'])).

I have tried commenting out all the lines below, but ever time the page is blank. No errors, warnings, nothing.

Doe's that make sense?

 

 

Thank you

 

The Page

-----------------------

<?php
		 	if ((!isset($_POST['email'])) || (strlen($_POST['name']) == 0) || (strlen($_POST['email']) == 0) || (strlen($_POST['alias']) == 0) || (strlen($_POST['password']) == 0) || (strlen($_POST['retype']) == 0))
		 	{
		 		WriteForm("Please complete all fields.");
			}
			else
			{
				require_once("includes/user.class.php");
				$user = new user();
				if (!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email']))
				{
					WriteForm("Invalid email address.");
				}
				elseif ($user->loademail($_POST['email']))
				{
					WriteForm("Email address has already been registered.");
				}
				elseif ($user->loadalias($_POST['alias']))
				{
					WriteForm("Alias has already been taken by another user.");
				}		
				elseif (strlen($_POST['password']) < 
				{
					WriteForm("Password must be at least 8 characters long.");
				}
				elseif ($_POST['password'] != $_POST['retype'])
				{
					WriteForm("Your passwords don't match.");
				}
				else
				{
					$user->name = $_POST['name'];
					$user->email = $_POST['email'];
					$user->setpassword($_POST['password']);
					$user->alias = $_POST['alias'];
					$user->save();
					$_SESSION['user'] = $user;
					WriteForm("COMPLETE");
				}
			}
			?>

 

The WriteForm method just has echo $message; Nothing else.

 

-----------------

The user class

<?php

class user
{
public $id;
public $name;
public $email;
public $alias;
public $password;
public $dob;
public $locationid;

protected $db;

function user()
{
	require_once("config.php");
	require_once("db.class.php");
	$this->db = new db();
}

public function setpassword($password)
{
	if (strlen($password) < 
	{
		return false;	
	}	
	$this->password = md5($password);
	return true;
}	

public function checkpassword($password)
{
	if ($this->password == md5($password))
	{
		return true;
	}	
	return false;
}

public function loademail($email)
{
	$this->db->connect();
	$result = $this->db->queryone("SELECT * FROM users WHERE email='" . $email . "'");	
	if ($result)
	{
		$this->id = $result['id'];
		$this->name = $result['name'];
		$this->email = $result['email'];
		$this->alias = $result['alias'];
		$this->password = $result['password'];
		$this->dob = $result['dob'];
		$this->locationid = $result['locationid'];
		$this->db->disconnect();
		return true;
	}
	$this->db->disconnect();
	return false;
}

public function loadalias($alias)
{
	$this->db->connect();
	$result = $this->db->queryone("SELECT * FROM users WHERE alias='" . $alias . "'");	
	if ($result)
	{
		$this->id = $result['id'];
		$this->name = $result['name'];
		$this->email = $result['email'];
		$this->alias = $result['alias'];
		$this->password = $result['password'];
		$this->dob = $result['dob'];
		$this->locationid = $result['locationid'];
		$this->db->disconnect();
		return true;
	}
	$this->db->disconnect();
	return false;
}

public function save()
{
	$this->db->connect();
	if (isset($this->id))
		$this->db->nonquery("UPDATE users SET email='" . $this->email . "', password='" . $this->password . "', name='" . $this->name . "', dob='" . $this->dob . "', alias='" . $this->alias . "', locationid='" . $this->locationid . "' WHERE id='" . $this->id . "'");
	else
		$this->db->nonquery("INSERT INTO users VALUES ('', '" . $this->email . "','" . $this->password . "','" . $this->name . "','" . $this->dob . "','" . $this->alias . "','" . $this->locationid . "')");
	$this->db->disconnect();
}

public function delete()
{
	$this->db->connect();
	if (isset($this->id))
	$this->db->nonquery("DELETE FROM users WHERE id='" . $this->id . "'");
	$this->db->disconnect();
}
}

?>

Hi,

 

Thanks for the tip, I have done as you suggested and no errors where thrown.

 

Here is the page: http://www.friendcodes.co.uk/register.php

 

If you fill in fake data, everything works fine up to the point after the check is done to see if the user exists.

I have a test user in the database email address bob@hope.com, his alias is Test User. I have been using it to check the form validation.

 

 

Any other thoughts?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • 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.