Hello i’m new in php. I start learning oop php and like all beginers i have a problem. I will post my code here. I cant past registration information from index.php to class.php I think the problem is in the index.php on line 8. Can someone help me:)
index.php
include_once "classes/class.php";
if (isset($_POST["submit"])) {
$register = new User();
$register->insertUser($_POST["name"],$_POST["lastname"],$_POST["username"],$_POST["email"],$_POST["password"]);
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Register</title>
</head>
<body>
<form method="POST" action="classes/class.php">
<h1>Welcome to register page</h1><hr><br>
Name: <input type="text" name="name" placeholder="Enter your name here..." required /><br><br>
Lastname: <input type="text" name="lastname" placeholder="Enter your lastname here..." required /><br><br>
Username: <input type="text" name="username" placeholder="Enter your username here..." required /><br><br>
E-mail: <input type="text" name="email" placeholder="Enter your E-mail here..." required /><br><br>
Password: <input type="password" name="password" placeholder="Enter your password here..." required /><br><br>
<input type="submit" name="submit" value="Register" />
</form><br>
If you alredy have accaunt logIn <a href="<?php echo 'logIn.php'; ?>">HERE</a>!
</body>
</html>
class.php
class User {
protected $dbHost = "localhost";
protected $dbUser = "root";
protected $dbPassword = "";
protected $dbName = "z7";
protected $dbConn;
public function __construct() {
$this->dbConn = mysqli_connect($this->dbHost,$this->dbUser,$this->dbPassword,$this->dbName);
if ($this->dbConn->connect_error) {
die("Connection to database faild " . $this->dbConn->connect_error);
}
}
public function insertUser($name,$lastname,$username,$email,$password) {
$sql = "INSERT INTO user(NAME,LASTNAME,USERNAME,EMAIL,PASSWORD)
VALUES('$name','$lastname','$username','$email','$password')";
$this->dbConn->query($sql);
}
}