[英]PHP Registration Form not saving
I have a HTML Sign Up form that allows new users to be registered to the site.: 我有一个HTML注册表格,该表格允许新用户注册到该站点。
<form action="register.php" method="POST" class="register-form">
<h1>Create Account</h1>
<label>
<span>First Name :</span>
<input id="firstname" type="text" name="firstname" placeholder="Your First Name" autocomplete="off" required/>
</label>
<label>
<span>Surname :</span>
<input id="surname" type="text" name="surname" placeholder="Your Surname" autocomplete="off" required/>
</label>
<label>
<span>Username :</span>
<input id="username" type="text" name="username" placeholder="Your Chosen Username" autocomplete="off" required/>
</label>
<label>
<span>Email :</span>
<input id="email" type="email" name="email" placeholder="Your Email Address" autocomplete="off" required/>
</label>
<label>
<span>Password :</span>
<input id="password" type="password" name="password" placeholder="Your Chosen Password" autocomplete="off" required/>
</label>
<hr>
<input name="action" type="hidden" value="signup" />
<input type="submit" class="btn register btn-success btn-lg" name="submit" value="Register">
</form>
Which goes to register.php: 哪个去register.php:
<?php
$connection = mysql_connect('localhost', 'root', 'password');
if (!$connection) {
die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db('gmaps1');
if (!$select_db) {
die("Database Selection Failed" . mysql_error());
}
// If the values are posted, insert them into the database.
if (isset($_POST['username']) && isset($_POST['password'])) {
$firstname = $_POST['firstname'];
$surname = $_POST['surname'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$query = "INSERT INTO `users` (firstname, surname, username, password, email) VALUES ('$firstname', '$surname', '$username', '$password', '$email')";
$result = mysql_query($query);
if ($result) {
header("Location: thank_you.html");
} else {
echo 'User Not Created';
}
}
?>
But when I click the Register button it doesn't save the data and returns "User Not Created". 但是,当我单击“注册”按钮时,它不会保存数据并返回“未创建用户”。 Would it be better using MySQLi rather than MySQL or is there a better way for this to work??
使用MySQLi而不是使用MySQLi会更好,还是有更好的方法呢?
Error checking solved my problem - "field 'active' doesn't have a default value" 错误检查解决了我的问题-“字段'active'没有默认值”
There was an inactive field in the table 'Users'. 表“用户”中有一个非活动字段。 I got rid of that and it works fine.
我摆脱了它,它工作正常。 It must have been added in by mistake.
它一定是错误添加的。
mysql_real_escape
and maybe a trim()
but thats just a starting point when it comes to security mysql_real_escape
,也可以使用trim()
但这仅是安全性的起点 echo $query
, open phpMyAdmin (for example) and copy-paste the output inside the SQL field and send -> you may get a MySQL error you can analyse echo $query
,打开phpMyAdmin(例如),然后将输出复制粘贴到SQL字段中并发送->您可能会得到一个MySQL错误,可以分析 It's better to store passwords hashed. 最好存储散列的密码。 Try inserting
MD5($password)
(there are way better options!) and on login do compare: 尝试插入
MD5($password)
(有更好的选择!),并在登录时进行比较:
if(MD5($inputPassword) == $passwordhashFromDatabase){} if(MD5($ inputPassword)== $ passwordhashFromDatabase){}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.