我有一个小问题。我有一张登记表。它工作得几乎完美,我可以检查输入字段的值,我可以检查天气我们在数据库中是否有相同的用户名,但如果一切正常,我无法将数据发送到我的数据库。我以管理员/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;
}
?>
最佳答案
看起来您的插入查询中有 shal(letter L) 而不是 sha1(# one)。打印出查询结果,您应该会看到您的问题。
关于php - 我无法将输入字段中的数据发送到我的 MySQL 数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44633516/