Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/288.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/78.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
php调用独立php文件后更新html_Php_Html_Forms_Login - Fatal编程技术网

php调用独立php文件后更新html

php调用独立php文件后更新html,php,html,forms,login,Php,Html,Forms,Login,我正在尝试为我的网站实现一个用户登录系统。我有一个newMember.html文件,其格式如下: <form method="post" action="nameValidation.php"> <p>Username:</p> <input type="text" name"user" required> <input name="submitButton" type="submit" value="Create a

我正在尝试为我的网站实现一个用户登录系统。我有一个newMember.html文件,其格式如下:

<form method="post" action="nameValidation.php">
    <p>Username:</p>
    <input type="text" name"user" required>
    <input name="submitButton" type="submit" value="Create account"/>
</form>
在nameValidation中,我检查用户名是否可用。如果不是,我想在输入字段旁边显示一条红色文本,您可以在其中输入用户名。我尝试了类似的操作,但出现了服务器错误:

内部nameValidation.php

<?php
    //connect to database, check the value of the username to see if it exists
    if (username already exists) {
        //keep the page that i had the way it was, 
        //just add a red sentence saying "username is already taken"
    }
    else {
       //tell the user he was successful in making an account,
       //and redirect him to my login page (already implemented)
    }       
?>
我不想使用内联php有两个原因

至少在我看来,它看起来杂乱无章,令人困惑

2我在其他stackoverflow帖子中读到这不是一个好的做法

如果有必要的话,我会使用内联php,但任何和所有的帮助都将不胜感激

使用web框架,如,或任何其他适合您的框架

PHP框架使用模板来容纳动态页面。它们通常允许在代码中使用特殊的快捷方式,这样您就不必编写任何“内联PHP”

这就是MVC模型视图控制器的心态:控制器控制视图中使用的实际数据,而不是视图

关于web框架已经足够了

要回答您的问题,首先将文件重命名为end in.php,以显示该文件包含php

接下来,编辑代码,以检查用户是否存在。最漂亮的内联PHP代码是通过在页面顶部完成所有工作并使用页面本身中生成的数据创建的

因此,对于您的HTML:

<?php

/* For example: */
$username = $_POST['username'];
$db = new DB(/* ... */);
$userNameExists = $db -> userNameExists ($username);

?>

<!-- The rest of the code of the page -->

<form method="post" action="nameValidation.php">
    <p>Username:</p>
    <input type="text" name"user" required value="<?php echo $username; ?>"><?php echo $userNameExists ? '<span class="error">Username already exists</span>' : '' ?>
    <input name="submitButton" type="submit" value="Create account"/>
</form>

内联php对您意味着什么?服务器错误消息是什么?谢谢,它现在工作正常。为了确保这一点,我将操作更改为文件名,特别是newMember.php,因为我不想再调用nameValidation.php了,对吗?无论如何。这就是我要找的。