简体   繁体   English

PHP Resistration页面将代码显示为纯文本

[英]PHP Resistration page is displaying code as plain text

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. 我正在尝试制作一个简单的用户注册页面,该页面从用户创建HTML页面输入输入并通过PHP页面进行验证。 Currently when I enter my credentials and press submit a page appears and shows the full PHP page as plain text. 目前,当我输入凭据并按提交时,将出现一个页面,并以纯文本形式显示完整的PHP页面。 The connection details are in Config.php 连接详细信息在Config.php中

I am running the file from a remote server on my browser. 我正在从浏览器上的远程服务器运行文件。

This is the registration PHP Code: 这是注册PHP代码:

   <?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”页面的代码。

<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? 如何使其正确显示并输入用户提供的详细信息?

Save your file with .php or .html extension. 使用.php或.html扩展名保存文件。 Hope this will work for you. 希望这对您有用。 And make sure you are running it on the local server. 并确保您正在本地服务器上运行它。

Ok, your server/plan has php enabled? 好的,您的服务器/计划已启用php?

Also, what is returned when you create a phpinfo page? 另外,创建phpinfo页面时返回什么? If you don't have one, put this in a page (like phpinfo.php), in the site root: 如果您没有,请将其放在站点根目录下的页面(如phpinfo.php)中:

<?php
phpinfo();
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM