少し問題があります。私は登録用紙を持っています。私は入力フィールドの値をチェックすることができます、私は天気を確認することができます私たちは、dbで同じユーザー名を持っていますが、すべてがOKであれば、私のデータベースにデータを送信することはできません。私は管理者/ rootとして使用するので、私は特権を持っています。何が問題ですか?助けてください!入力フィールドからMySQLデータベースにデータを送信できません
<?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パスワードハッシュ](https://konklone.com/post/why-google-is-hurrying-the-web-to-kill-sha-1)を使用しないでください。***または*** [MD5パスワードハッシュ](http://security.stackexchange.com/questions/19906/is-md5-considered-insecure)***そしてPHPの[組み込み関数](http: //jayblanchard.net/proper_password_hashing_with_PHP.html)を使用してパスワードセキュリティを処理します。ハッシュする前に[パスワードを逃さないでください](http://stackoverflow.com/q/36628418/1011527)を確認するか、他のクレンジングメカニズムを使用してください。パスワードを変更すると、パスワードが変更され、不要な追加のコーディングが発生します。 –
[Little Bobby](http://bobby-tables.com/)によると*** [あなたのスクリプトはSQLインジェクション攻撃の危険にさらされています。](http://stackoverflow.com/questions/60174/how-can- i-prevent-sql-in-php)***。 [文字列をエスケープする](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)でも安全ではありません! –
dd [エラー報告](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) ファイルの先頭に_whileあなたのPHPタグを開いた直後のtesting_例えば '<?php error_reporting(E_ALL); ini_set( 'display_errors'、1); '何かが得られるかどうかを調べる。 – RiggsFolly