gpt4 book ai didi

php - 在同一文件中使用 HTML 运行 PHP 脚本

转载 作者:太空宇宙 更新时间:2023-11-03 12:32:01 24 4
gpt4 key购买 nike

我正在尝试创建一个简单的 PHP 注册和登录表单。在向 register.php 文件添加样式和 HTML 之前,一切都按预期工作。现在,当点击注册时,不会说谢谢注册,什么也不会发生。

    <html>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="wrapper">
<div class="form">

<?php
echo "<h1>Register</h1>";

$submit = $_POST['submit'];

// form data

$fullname = STRIP_TAGS($_POST['fullname']);
$username = STRIP_TAGS($_POST['username']);
$password = STRIP_TAGS($_POST['password']);
$repeatpassword = STRIP_TAGS($_POST['repeatpassword']);
$date = date("Y-m-d");

if ($submit)
{
if($fullname&&$username&&password&&$repeatpassword)
{


if ($password==$repeatpassword)
{
//check char length of username and fullname
if(strlen($username)>25||strlen($fullname)>25)
{
echo "Length of username or fullname is too long!";
}
else
{ //check password length

if (strlen($password)>25||strlen($password)<6)
{
echo "Password must be between 6 and 25 characters";
}
else
{ //register the user!
// encrypt password
$password = md5($password);
$repeatpassword = md5($repeatpassword);

//open database

$connect = mysql_connect("localhost", "Matt", "password123");
mysql_select_db("phpsignin");

$queryreg = mysql_query("
INSERT INTO users VALUES ('','$fullname','$username','$password','$date')`

");

die ("Thankyou for registering! <a href='index.php'> Return to login page</a>");
}
}


}
else
echo "Your passwords do not match!";
}
else
echo "Please fill in <b>all</b> fields!";

}

?>
<form id="login" action='register.php' method='POST'>
<fieldset>
<ol>
<li>
<label>Your Full Name:
<input type="text" name='fullname' value='<?php echo $fullname; ?>'>
</label>
</li>

<li>
<label>Choose a username:
<input type="text" name='username' value='<?php echo $username;?>'>
</label>
</li>

<li>
<label>Choose a password:
<input type="password" name='password'>
</label>
</li>

<li>
<label>Confirm Your Password:
<input type="password" name='repeatpassword'>
</label>
</li>
</fieldset>
<div id="buttonHolder">
<button type="submit" name="submit">Register</button>
</div>
</form>

</div>
</div>
</body>
</html>

最佳答案

您的提交按钮没有,因此if ($submit) 永远不会是真实值,您的逻辑分支也永远不会运行。

关于php - 在同一文件中使用 HTML 运行 PHP 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14966288/

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