0

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?

stark
  • 287
  • 4
  • 9
  • 20

2 Answers2

2

Save your file with .php or .html extension. Hope this will work for you. And make sure you are running it on the local server.

Abdul Moiz
  • 1,317
  • 2
  • 17
  • 40
0

Ok, your server/plan has php enabled?

Also, what is returned when you create a phpinfo page? If you don't have one, put this in a page (like phpinfo.php), in the site root:

<?php
phpinfo();
?>
Dimas Pante
  • 2,466
  • 22
  • 30