【发布时间】:2020-12-04 23:47:30
【问题描述】:
我有两个相似的表格,都写入同一个数据库,但不同的表。 使用相同类型的字段,varchar。
当我在两个表单上发布数据时,我都会收到一条成功的消息,假设只有在数据成功写入数据库后才会出现。使用以下教程创建了我的第一个表单:“https://www.youtube.com/watch?v=LC9GaXkdxF8&t=4482s”。试图基于它创建一个注册和登录系统,但数据没有写入数据库。
一种形式(一种来自视频)正在将数据写入数据库,另一种则不是。不知道是什么原因。 有人知道可能是什么问题吗?
工作并写入数据库的表单:
<form action="includes/signup.inc.php" method="post">
<input type="text" name="uid" placeholder="Username">
<input type="text" name="mail" placeholder="E-mail">
<input type="password" name="pwd" placeholder="Password">
<input type="password" name="pwd-repeat" placeholder="Repeat Password">
<button type="submit" name="signup-submit">Signup</button>
<?php
//if an error occurs
if (isset($_GET['error'])) {
if ($_GET['error'] == 'emptyfields') {
echo '<p>Fill in all the fields!</p>';
}
else if ($_GET['error'] == 'invaliduidmail') {
echo '<p>Invalid username and email</p>';
}
else if ($_GET['error'] == 'invaliduid') {
echo '<p>Invalid username</p>';
}
else if ($_GET['error'] == 'invalidmail') {
echo '<p>Invalid email</p>';
}
else if ($_GET['error'] == 'passwordcheck') {
echo '<p>Passwords do not match</p>';
}
else if ($_GET['error'] == 'usertaken') {
echo '<p>Username is alread used!</p>';
}
}
//if succesfull
else if (isset($_GET['signup']) == 'success'){
echo '<p>signup succesfull!!!</p>';
}
?>
</form>
下面的表格似乎不起作用。 (请注意,当我添加了更多字段时,我确实对 PHP 文件 include/signup.inc.php 做了一些小改动) 由于某种原因,以下标记未出现在堆栈溢出中
"form action="includes/signup.inc.php" class="form-signin" method="post"" 但我确实添加了它,所以引用它以查看它是否可见。
<h1 class="h3 mb-3 font-weight-normal">Create Account</h1>
<label for="inputUserName" class="sr-only">User Name</label>
<input name="userName" type="text" id="inputUserName" class="form-control" placeholder="User Name" >
<label for="inputFullName" class="sr-only">Full Name</label>
<input name="FullName" type="text" id="inputFullName" class="form-control" placeholder="Full Name" >
<label for="inputAge" class="sr-only">Age</label>
<input name="Age" type="text" id="inputAge" class="form-control" placeholder="Age" >
<label for="inputEmail" class="sr-only">Email address</label>
<input name="Email" type="text" id="inputEmail" class="form-control" placeholder="Email" >
<label for="inputPhoneNumber" class="sr-only">Phone Number</label>
<input name="Contact" type="tel" id="inputPhoneNumber" class="form-control" placeholder="Phone Number" >
<label for="inputPassword" class="sr-only">Password</label>
<input name="pwd" type="password" id="inputPassword" class="form-control" placeholder="Password" >
<label for="inputPassword" class="sr-only">Confirm Password</label>
<input name="ConfirmPwd" type="password" id="inputConfirmPassword" class="form-control" placeholder="Confirm Password" >
<button type="submit" name="signup-submit" class="btn btn-lg btn-primary btn-block" >Register</button>
<p class="text-center">Already Registered? <a href="SignIn.php">Sign in here</a> </p>
<?php
//check for errors on the FORM
//if an error occurs
if (isset($_GET['error'])) {
if ($_GET['error'] == 'emptyfields') {
echo '<p>Fill in all the fields!</p>';
}
else if ($_GET['error'] == 'invaliduidmail') {
echo '<p>Invalid username and email</p>';
}
else if ($_GET['error'] == 'invaliduid') {
echo '<p>Invalid username</p>';
}
else if ($_GET['error'] == 'invalidmail') {
echo '<p>Invalid email</p>';
}
else if ($_GET['error'] == 'passwordcheck') {
echo '<p>Passwords do not match</p>';
}
else if ($_GET['error'] == 'usertaken') {
echo '<p>Username is alread used!</p>';
}
}
//if succesfull
else if (isset($_GET['signup']) == 'success'){
echo '<p>Register was succesfull!!!</p>';
}
?>
</form>
【问题讨论】:
-
欢迎来到 Stack Overflow。第二种表格的代码不完整 - 请编辑您的问题以在 minimal,reproducible example 中包含所有相关代码,以便我们提供帮助 - 我们还需要查看处理表格的代码,因为这可能是问题所在。还请包括任何错误消息的详细信息(在屏幕上、日志中等)以及究竟出了什么问题的详细信息 - 当我们不知道它是什么时,很难帮助解决问题:)