Cant past variable information

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);

	}

}

test if $this->dbConn->query($sql) returns FALSE and if so show mysqli_error().

Offtopic: You should escape your data with mysqli_real_escape_string() or use prepared statements.

Problem was in form “action have to be #”. Thanks anyway :slight_smile:

Actually the action attribute shouldn’t even be in the form html if you are submitting to the same page.

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service