我有点问题。我有一个注册表。它几乎完美地工作,我可以检查输入字段的值,我可以检查天气我们在数据库中有相同的用户名,但如果一切正常,我无法将数据发送到我的数据库。我用它作为管理员/ root,所以我有权限。问题是什么?请帮助!
<?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;
}
?>
答案 0 :(得分:0)
在插入查询中看起来你有shal(字母L)而不是sha1(#one)。从查询中打印出您的结果,您应该会看到您的问题。