<?php
class connectDB {
private $db_user,
$db_pass,
$db,
$error,
$dsn;
public $pdo;
public function __construct($db_user, $db_pass, $db)
{
$this->db_user = $db_user;
$this->db_pass = $db_pass;
$this->db = $db;
$this->dsn = "mysql:host=localhost;dbname=" . $this->db;
}
public function connect()
{
$user = $this->db_user; // This seemed to
$pass = $this->db_pass; // fix an undefined
$dsn = $this->dsn; // error. Not sure why ..
try
{
//$this->pdo = new PDO($this->dsn, $this->user, $this->pass); - undefined
$this->pdo = new PDO($dsn, $user, $pass); // gives no error
}
catch (PDOException $e)
{
$this->error = "Connection Failed: " . $e->getMessage();
}
}
public function getError(){ return $this->error; }
}
class session {
private $email,
$userid,
$password,
$firstname,
$surname,
$query_login,
$query_register,
$reg_result,
$log_result,
$db_user,
$db_pass,
$db;
public function __construct($db_user, $db_pass, $db)
{
$this->db_user = $db_user;
$this->db_pass = $db_pass;
$this->db = $db;
}
public function register($email, $password, $firstname, $surname, $query)
{
$this->email = $email;
$this->password = $password;
$this->firstname = $firstname;
$this->surname = $surname;
$this->query_register = $query;
$array = array(
'email' => $this->email,
'password' => hash('sha256', "mysalt" . $this->password),
'firstname' => $this->firstname,
'surname' => $this->surname
);
$this->connection = new connectDB($this->db_user, $this->db_pass, $this->db);
$this->connection->connect();
$ps = $this->connection->pdo->prepare($this->query_register); //not too sure if this is valid
$this->reg_result = $ps->execute($array);
}
public function getRegResult()
{
return $this->reg_result;
}
}
?>
and index.php has:
<?php
require_once("require/session.php");
error_reporting(E_ALL);
$session = new session("user","pass","database"); //database credentials
$query = "INSERT INTO users (email, password, firstname, surname) VALUES ( :email, :password, :firstname, :surname )";
$session->register("me@email.com", "password", "John", "Smith", $query);
$result = $session->getRegResult();
if($result)
{
echo "Registration was succesful!";
}
else
{
echo $session->getError();
}
?>
I think I've really gone off the rails here somewhere.. I'm not getting any exception errors, or any php errors in my IDE.
Sorry for the amount of code, but I have no idea where the server error is coming from. Any and all help is much appreciated.

New Topic/Question
Reply




MultiQuote








|