【发布时间】:2017-11-21 20:15:39
【问题描述】:
我有一个小问题。我有一个注册表。它工作得几乎完美,我可以检查输入字段的值,我可以检查天气我们在数据库中是否有相同的用户名,但如果一切正常,我无法将数据发送到我的数据库。我使用它作为管理员/根,所以我有特权。问题是什么?请帮忙!
<?php
// declaring variables from input fields
$email = $_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];
$password2=$_POST['password2'];
function registration ($username, $email, $password) {
//new user registering
//return true or errormessage
//connecting to database, YEAH IT WORKS!
$connection = connecting_to_db();
//checking unique of username and IT WORKS!
$result = $connection->query("SELECT * FROM user WHERE username='".$username."'");
if (!$result) {
throw new Exception ('We couldnt query. Sorry.');
}
if ($result->num_rows>0) {
throw new Exception ('We have already this username! Choose something else!');
}
// if it is OK send it to the DB AND THIS IS NOT WORKING :-(
$result = $connection->query("INSERT INTO user VALUES'".$username."', shal('".$password."'), '".$email."')");
// I get alwasy this way and get this message.
if (!$result) {
throw new Exception ('We couldnt save your datas in our database. Try it later!');
}
return true;
}
?>
【问题讨论】:
-
你不应该使用 SHA1 password hashes 或 MD5 password hashes 而你真的应该使用 PHP 的built-in functions 来处理密码安全。确保你 don't escape passwords 或在散列之前对它们使用任何其他清理机制。这样做会更改密码并导致不必要的额外编码。
-
dd error reporting 到你的文件顶部测试时在你打开 PHP 标记之后,例如
<?php error_reporting(E_ALL); ini_set('display_errors', 1);看看它是否产生任何东西。跨度> -
我实际上没有看到你调用函数的任何地方
-
如果您实际检查错误而不只是检查它是否返回真值,这会有所帮助。那样你得不到任何好的信息。
标签: php mysql registration user-registration