diff --git a/index.php b/index.php index 4f0fb61..91e4f94 100644 --- a/index.php +++ b/index.php @@ -66,12 +66,23 @@ session_start(); if (str_starts_with($_POST["sub"], "Registrovat")) { + $failed = false; + $database -> query("INSERT INTO user_info (nickname) VALUES (\"" . $safe_uname . "\")"); $key_id_out = $database -> query("SELECT id FROM user_info WHERE nickname=\"" . $safe_uname . "\""); - $database -> query("INSERT INTO user (username, password, user_info) VALUES (\"" . $safe_uname . "\",\"" . $hashed_pass ."\", " . ($key_id_out -> fetch_assoc())["id"] . ")"); + try + { + $database -> query("INSERT INTO user (username, password, user_info) VALUES (\"" . $safe_uname . "\",\"" . $hashed_pass ."\", " . ($key_id_out -> fetch_assoc())["id"] . ")"); + } catch (mysqli_sql_exception $e) + { + $failed = true; + $database -> query("DELETE FROM user_info WHERE nickname=\"" . $safe_uname . "\""); - login($safe_uname); + echo ""; + } + + if (!$failed) login($safe_uname); } else { $res = $database -> query("SELECT username, password FROM user WHERE BINARY username=\"" . $safe_uname . "\" AND BINARY password = \"" . $hashed_pass . "\"");