loginChange.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. $host = "provalgk.beget.tech";
  3. $username = "provalgk_user";
  4. $password = "Qwer123.";
  5. $database = "provalgk_user";
  6. $login = $_POST["login"];
  7. $mysql = mysqli_connect($host, $username, $password, $database);
  8. // Проверка соединения
  9. if($mysql->connect_error){
  10. die("Ошибка подключения". $mysql->connect_error);
  11. }
  12. // Получение данных пользователя из базы данных
  13. session_start();
  14. if (isset ($login))
  15. if (isset ($_SESSION['id']))
  16. $user_id = $_SESSION['id'];
  17. $userlogin = $_SESSION['login'];
  18. $quary = "SELECT * FROM Login WHERE login like'$login'";
  19. $result = mysqli_query($mysql, $quary);
  20. if(mysqli_num_rows($result) > 0 && $userlogin == $login)
  21. {
  22. header('Location: LoginChange.html?message=Логины+совпадают');
  23. mysqli_close();
  24. session_abort();
  25. }
  26. if(mysqli_num_rows($result) > 0 && $userlogin != $login)
  27. {
  28. header('Location: LoginChange.html?message=Логин+существует');
  29. mysqli_close();
  30. session_abort();
  31. }
  32. session_abort();
  33. if($userlogin != $login && mysqli_num_rows($result) == 0)
  34. {
  35. $query = "UPDATE Login SET login = '$login' WHERE id_user = $user_id";
  36. if($res = mysqli_query($mysql, $query))
  37. {
  38. session_start();
  39. $_SESSION['login'] = $login;
  40. echo "<script>localStorage.setItem('login', '$login');
  41. window.location.href = 'UserAccount.html';</script>";
  42. }
  43. }
  44. ?>