From 888c7a5019c73d11cd9c9113feee2d54ebd28b41 Mon Sep 17 00:00:00 2001 From: ENGO150 Date: Tue, 21 May 2024 19:20:18 +0200 Subject: [PATCH] fixed invalid register username problems --- index.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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 . "\"");