Answer the question
In order to leave comments, you need to log in
When you try to change a user's login, the logins of all users in the database change. How to fix?
Hello! I am making a form for editing a personal account for a site user. When you try to change a user's login, the logins of all users in the database change. I understand that the error is in the "WHERE id = id" condition, but I don't know how to fix it so that everything works correctly.
<?php
require("../db.php");
?>
<? session_start() ?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Login</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="reset.css">
</head>
<body>
<div class="container">
<?php
$GLOBALS['link'] = mysqli_connect("localhost", "root", "", "lesko") or die ("Нет соединения");
mysqli_set_charset($link, 'utf8');
?>
<?
var_dump ($_SESSION['login']);
$query = "UPDATE users SET login='$_POST[new_login]' WHERE id= id";
if (!mysqli_query($GLOBALS['link'], $query))
echo "ошибка $query<br/>" .
mysqli_error($GLOBALS['link'])."<br /><br />";
$result = mysqli_query($GLOBALS['link'], $query);
?>
</div>
Профиль пользователя<br>
ваш логин : <?=$_SESSION['login']->login;?> <br>
<?
if (isset($_POST['change_login'])) {
$error = array();
if ($_POST['new_login'] == '') {
$error[] = 'Введите новый логин' ;
}
if ($_POST['new_login'] == $_SESSION['login']->login) {
$error[] = 'Введите новый логин' ;
}
if (empty($error)) {
$query = "UPDATE users SET login ='$_POST[new_login]' WHERE id = id";
if (!mysqli_query($GLOBALS['link'], $query))
$result = mysqli_query($GLOBALS['link'], $query);
echo 'логин изменен на '.$_POST['new_login'].'';
}else {
echo array_shift($error);
}
}
?>
<form action="" method="POST">
<input type="text" name="new_login" class="form-control" style="width:auto;px;">
<button type="submit" name="change_login" class="btn btn-warning"> Изменить логин </button>
</form>
<br>
Логин: <?=$_SESSION['login']->login;?> <br>
Пароль: <?=$_SESSION['login']->password;?> <br>
<a href="/logoout" class="btn btn-danger">Выйти из аккаунта</a>
</body>
</html>
Answer the question
In order to leave comments, you need to log in
WHERE id= id
cant tut
expression is known to be always true for all rows in the table.
although in general the code itself is some kind of big cant.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question