I am trying to make a simple user registration page that enters input form a user creation HTML page and validates through a PHP page. Currently when I enter my credentials and press submit a page appears and shows the full PHP page as plain text. The connection details are in Config.php
I am running the file from a remote server on my browser.
This is the registration PHP Code:
<?php
session_start();
require_once__DIR__.'/config.php';
//MAKE A CONNETION TO THE DATABASE
$dbh= new PDO (
'mysql:host=' . DB_HOST . '; dbname=' . DB_USERNAME,
DB_USERNAME,
DB_PASSWORD
);
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$sql = "INSERT INTO users ( username, password, email) VALUES ( :username, :password, :email )";
$query = $dbh->prepare( $sql );
$query->execute( array( ':username'=>$username, ':password'=>$password, ':address'=>$address, ':email'=>$email ) );
$result = $query->execute( array( ':username'=>$username, ':password'=>$password, ':email'=>$email ) );
if ( $result ){
echo "<p>Your Registration is complete</p>";
} else {
echo "<p>There was a problem with registration, please try again.</p>";
}
?>
The following is the code from the create html page.
<html>
<body>
<form action="../user_create.php" method="POST">
username: <input type="text" name="username"/>
password: <input type="text" name="password"/>
email: <input type="text" name="email"/>
<input type="submit" value="user_create"/>
</form>
</body>
</html>
How can I get it to display correctly and enter the details provided by the user?