I think im utilizing php oop right, however its not redirecting the page to the profile.php page it just goes blank after i submit.
No error message shows, i wonder what im dong wrong.
Could it be a session problem ?
index.php
<?php
error_reporting(-1);
require_once 'layouts/header.php';
require_once 'User.php';
session_start();
if (isset($_POST['btn-signup']) ){
$username = htmlentities($_POST['txt-username']);
$unpass = htmlentities($_POST['txt-password']);
$password = password_hash($unpass, PASSWORD_BCRYPT, ['cost' => 12] );
$unemail = $_POST['txt-email'];
$email = filter_var($unemail, FILTER_VALIDATE_EMAIL);
$guest = new User();
if($username ==""){
echo "Enter a Username";
}
if($email == ""){
echo "Enter a Email";
}
if($password == ""){
echo "Enter a Password";
}
elseif($guest->signup($email,$password,$username)){
header("Location:profile.php");
}
}
?>
<div class="container">
<div class="row">
<form action ="" method="POST">
<div class="form-group">
<label for="Email">Email address</label>
<input type="email" class="form-control" aria-describedby="emailHelp" name="txt-email" placeholder="Enter email">
</div>
<div class="form-group">
<label for="Username">Username</label>
<input type="text" class="form-control" name="txt-username" aria-describedby="emailHelp" name="txt-username" placeholder="Enter Username">
</div>
<div class="form-group">
<label for="Password">Password</label>
<input type="password" class="form-control" name="txt-password" aria-describedby="emailHelp" name="txt-password" placeholder="Enter email">
</div>
<button type="submit" name="btn-signup" class="btn btn-primary">Submit</button>
</form>
</div>
</div>
</body>
</html>
User.php
<?php
require_once 'Db.php';
class User extends Db{
private $db;
public function __construct()
{
$this->db = new Db();
}
public function signup($email, $password, $username)
{
try{
$stmt = $this->db->connect->prepare("INSERT INTO users (user_email, user_pass, user_name) VALUES (:email, :password, :username) ");
$stmt->bindparam(':email', $email);
$stmt->bindparam(':password', $password);
$stmt->bindparam(':username', $username);
$stmt->execute();
}
catch(PDOExeception $e)
{
echo $e->getMessage();
}
}
}
Db.php
<?php
error_reporting(-1);
class Db{
private $db_host;
private $db_user;
private $db_name;
private $db_pass;
public function connect()
{
$this->db_host = "127.0.0.1";
$this->db_user = "root";
$this->db_pass = "root";
$this->db_name = "eli9";
try {
$db = new PDO("mysql:host=127.0.0.1;port=8889,dbname=eli9", 'root', 'root');
$db->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
echo "connected \n";
}
catch (PDOException $e){
echo $e->getMessage();
}
return $db;
}
}
htmlentities()against passwords (or any other form of manipulation) since it could do more damage than good when usingpassword_verify()and will fail. You also gave the inputs 2x name attributes of the same.name="xxx"twice; you need to remove one of them from those. That could be having some adverse effects.'btn_signup'