我想在注册过程中工作,在谷歌和Youtube的帮助下,我已经创建了“登录和唱歌”页面与切换选项,但无法运行registration.php文件一旦用户提供注册信息在login.html文件。代码如下:
<form id="login" class="input-group">
<input type="text" class="input-field" placeholder="User Id" required>
<input type="password" class="input-field" placeholder="Enter Password" required>
<input type="checkbox" class="check-box"><span>Remember Password</span>
<button type="submit" class="submit-btn">Sign-In</button>
</form>
<form Id="register" class="input-group">
<input type="text" class="input-field" placeholder="User Id" required>
<input type="email" class="input-field" placeholder="Email Id" required>
<input type="password" class="input-field" placeholder="Enter Password" required>
<input type="password" class="input-field" placeholder="Confirm Password" required>
<input type="phone-number" class="input-field" placeholder="Mobile Number" required>
<input type="checkbox" class="check-box"><span>I agree to the terms & conditions</span>
<button type="submit" class="submit-btn">Sign-Up</button>
</form>如何在login.html文件中点击注册按钮执行registration.php文件?登录选项也是如此。
发布于 2019-10-23 14:02:43
method属性指定如何发送表单数据(表单数据被发送到action属性中指定的页面)。
表单数据可以作为URL变量(使用method="get")或HTTP post事务(使用method="post")发送。
请查看此处了解更多详细信息w3schools
<form id="login" class="input-group" method="POST" action="file_path/login.php">
<input type="text" class="input-field" placeholder="User Id" required>
<input type="password" class="input-field" placeholder="Enter Password" required>
<input type="checkbox" class="check-box"><span>Remember Password</span>
<input type="submit" class="submit-btn" value="Sign-In">
</form>
<form Id="register" class="input-group" method="POST" action="file_path/register.php">
<input type="text" class="input-field" placeholder="User Id" required>
<input type="email" class="input-field" placeholder="Email Id" required>
<input type="password" class="input-field" placeholder="Enter Password" required>
<input type="password" class="input-field" placeholder="Confirm Password" required>
<input type="phone-number" class="input-field" placeholder="Mobile Number" required>
<input type="checkbox" class="check-box"><span>I agree to the terms & conditions</span>
<input type="submit" class="submit-btn" value="Sign-Up">
</form>根据您的评论进行编辑
将按钮替换为输入type="submit“,并将@放在php变量前,这样就不会收到未定义的错误通知(@用于避免错误通知)
<div class="header">
<h2>Register here</h2>
</div>
<form method="post" action="register.php">
<?php include('errors.php'); ?>
<div class="input-group">
<label>Username</label>
<input type="text" name="username" value="<?php echo @$username; ?>">
</div>
<div class="input-group">
<label>Email</label>
<input type="email" name="email" value="<?php echo @$email; ?>">
</div>
<div class="input-group">
<label>Password</label>
<input type="password" name="password_1">
</div>
<div class="input-group">
<label>Confirm Password</label>
<input type="password" name="password_2">
</div>
<div class="input-group">
<label>Mobile number</label>
<input type="number" name="mobile" value="<?php echo @$mobile; ?>">
</div>
<div class="input-group">
<input type="submit" class="btn" name="reg_user" value="Sign-Up">
</div>
</form>在register.php中创建register.php文件
<?php
$con = mysqli_connect("localhost", "username", "password", "dbname") or trigger_error("Unable to connect to the database");
if(isset($_POST['reg_user'])){
$name = $_POST['username']; //here "username" is what you defined in the "name" field of input form
//define other variables
//write your own sql query , here is an example
$query = "INSERT INTO table(name) VALUES(?)";
$stmt = mysqli_stmt_init($con);
if(!mysqli_stmt_prepare($stmt,$query)){
echo "Error";
}else{
mysqli_stmt_bind_param($stmt,"s",$name);
mysqli_stmt_execute($stmt);
}
}
?>发布于 2019-10-23 14:55:45
确保在表单中添加method="POST"、action="path/function.php"和name="desiredName",如下所示:
<form id="login" class="input-group" method="POST" action="file_path/login.php">
<input type="text" class="input-field" placeholder="User Id" name ="user" required>
<input type="password" class="input-field" placeholder="Enter Password" name="password" required>
<input type="checkbox" class="check-box"><span>Remember Password</span>
<button type="submit" class="submit-btn">Sign-In</button>
</form>然后在PHP中,为了“捕捉”post中的数据,您将使用如下代码:
$this->getpost['user'];或
$_POST['user'];https://stackoverflow.com/questions/58516281
复制相似问题