gpt4 book ai didi

php - 注册页面上的操作 ="???"应该是什么?

转载 作者:行者123 更新时间:2023-11-29 08:25:42 24 4
gpt4 key购买 nike

好的,所以我引用了各个网站编写了这段代码。我正在尝试为网站编写一个注册页面。 html表单如何连接到PHP/如何连接?

我知道我搞砸的地方是表单中的action=""。不同的网站告诉我要放入不同的内容,从服务器名称(“localhost”)到“”到 php 所在文件的名称(我想在与表单相同的文件中执行此操作,如果是可能的,我尝试了这两个文件和一个单独的文件)。我应该在那里放置什么,以便当单击“提交”时,它会在与表单相同的屏幕上给出错误消息,并且当单击“提交”并且没有错误消息时,它会继续?我应该将其继续的页面链接到哪里?

另外,请告诉我我的代码是否已被弃用。我一直在尝试检查所有内容,但我可能会错过一些东西。

<?php
include 'connect.php';


//if submit is clicked
if (isset($_POST['submit'])) {
//then check if all fields are filled
if (!$_POST['username'] | !$_POST['password'] | !$_POST['firstname'] | !$_POST['MI'] | !$_POST['lastname'] | !$_POST['email'] | !$_POST['phonenumber'] | !$_POST['country'] ) {
die('You did not complete all of the required fields'); }

$usernamesquery = mysql_query("SELECT * FROM logins WHERE username='$usernametest'");
if(mysqli_stmt_num_rows($usernamesquery) > 0) {
die('This username is already taken.');
}


}

?>
<form action="????????" method="post">

Username: <input type="text" name="username" maxlength="30"><br>
Password: <input type="password" name="password" maxlength="30"><br>
First Name: <input type="text" name="firstname" maxlength="30"><br>
Middle Initial: <input type="password" name="MI" maxlength="30"><br>
Last Name: <input type="text" name="lastname" maxlength="30"><br>
Email: <input type="password" name="email" maxlength="50"><br>
Phone Number: <input type="text" name="phonenumber" maxlength="11"><br>
Country: <input type="password" name="country" maxlength="40"><br>
<input type="submit">
</form>

最佳答案

如果您希望它定向到同一个文件,则只需使用:

<form action="" method="POST">

此外,由于您没有为提交按钮命名,因此没有 $_POST["submit"]

<input type="submit" name="submit">

此外,$usernametest实际上包含什么内容吗?因为您没有在上面的代码中为其指定值。

关于php - 注册页面上的操作 ="???"应该是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18012784/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com