NSA
sudo apt-get thefuckout.tar.gz
- Dec 9, 2011
- 715
- 86
Hola.
So first of all, I'll show you the problem then explain.
Now, you can see I'm printing out two arrays.
However, they're the exact same arrays.
For some reason, the second array doesn't match the first array.
Now, you could say that it's not really a problem, because it's working in the first array,
however it's the second array that I need the most.
If you can help me with this, it'd be appreciated.
Here's my current code:
It's all a bit messy at the moment, but don't worry about that.
Thanks!
So first of all, I'll show you the problem then explain.
Now, you can see I'm printing out two arrays.
However, they're the exact same arrays.
For some reason, the second array doesn't match the first array.
Now, you could say that it's not really a problem, because it's working in the first array,
however it's the second array that I need the most.
If you can help me with this, it'd be appreciated.
Here's my current code:
PHP:
<?php
class user
{
public $con;
public $username;
public $password;
public $email;
public $error = array();
public $success;
public function __construct()
{
$this->con = new mysqli("localhost", "root", "", "cms");
if(isset($_POST['reg_x_21']))
{
$this->init();
$this->error = array();
}
}
public function init()
{
$this->username = $_POST['username'];
$this->password = $_POST['password'];
$this->email = $_POST['email'];
$this->init_reg();
}
public function checkUsername()
{
$username = $this->username;
$sql = "SELECT * FROM users WHERE username = ?";
if($stmt = $this->con->prepare($sql))
{
$stmt->bind_param("s", $username);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows == 1)
{
$this->error['username'] = "Username is already taken.";
var_dump($this->error);
return false;
}
else
{
$this->success['username'] = "Username is free.";
return true;
}
}
else
{
$this->error['system'] = "Database error when checking the username is already taken.";
return false;
}
}
public function checkEmail()
{
$email = $this->email;
$sql = "SELECT * FROM users WHERE email = ?";
if($stmt = $this->con->prepare($sql))
{
$stmt->bind_param("s", $email);
$stmt->execute();
$stmt->store_result();
if($stmt->num_rows == 1)
{
$this->error['email'] = "An account with this e-mail already exists.";
return false;
}
else
{
$this->success['email'] = "Email is free.";
return true;
}
}
else
{
$this->error['email'] = "This email already belongs to an account";
return false;
}
}
public function checkPassword($password)
{
$password = $this->password;
if($password)
{
return true;
}
else
{
$this->error['password'] = "Password error.";
return false;
}
}
public function init_reg()
{
$username = $this->checkUsername();
$email = $this->checkEmail();
$password = $this->checkEmail();
if($username == true)
{
if($email == true)
{
if($password == true)
{
$this->register();
}
else
{
return $this->error['password'];
}
}
else
{
return $this->error['email'];
}
}
else
{
return $this->error['username'];
}
}
public function register()
{
if($this->error == null)
{
$username = $this->username;
$password = $this->password;
$groupID = 1;
$email = $this->email;
$registered = date("d/m/Y");
$stmt = $this->con->prepare("INSERT INTO users (username, groupid, password, email, registered) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sisss", $username, $groupID, $password, $email, $registered);
$stmt->execute();
$this->success = "Thanks for signing up, " . $username;
}
else
{
return $this->error;
}
}
}
$user = new user();
?>
It's all a bit messy at the moment, but don't worry about that.
Thanks!