Строковое значение запроса не извлекается
Я не могу прочитать идентификатор из строки запроса.
Когда я нажимаю ссылку Изменить, я правильно читаю строку без каких-либо проблем, но когда я обновляю идентификатор данных, он не извлекается, и, следовательно, мой запрос не работает.
$id = $_GET['id']; set null when clicking update button. thats why query is not running
Что я уже пробовал:
<?php include 'master/header.php'; include 'config.php'; include './functions/functions.php'; ?> <?php $id = ""; if (isset($_GET['id'])) { $id = $_GET['id']; } $sql = "SELECT * FROM user WHERE id =$id "; $result = $conn->query($sql); $row = mysqli_fetch_assoc($result); if (isset($_POST['submit'])) { $firstName = $_POST['firstName']; $lastName = $_POST['lastName']; $email = $_POST['email']; $username = $_POST['username']; $password = $_POST['password']; $query = "UPDATE user SET firstname='$firstName',lastName='$lastName',email='$email',username='$username',password='$password' WHERE id= $id"; echo $query; $updateResult = $conn->query($query); if (!$updateResult ) { die("qery not works" . mysqli_error($conn)); } else { header("location: index.php"); } } ?> <h1 class="text-center">Edit User</h1> <form action="edit.php" method="post"> <div class="container"> <div class="row"> <input type="hidden" class="" for="" value="<?php ?>"> <label class="col-lg-6" for="firstName">First name</label> <input type="text" class="form-control col-lg-6" maxlength="25" name="firstName" placeholder="Enter First name" value="<?php if (isset($row['firstname'])) { echo $row['firstname']; } ?>" > </div> <div class="row"> <label class="col-lg-6" for="lastName">Last name</label> <input type="text" maxlength="25" class="form-control col-lg-6" name="lastName" placeholder="Enter Last name" value="<?php if (isset($row['lastName'])) { echo $row['lastName']; } ?>" > </div> <div class="row"> <label class="col-lg-6" maxlength="50" for="lastName">Email</label> <input type="text" class="form-control col-lg-6" name="email" placeholder="Enter Email" value="<?php if (isset($row['email'])) { echo $row['email']; } ?>" > </div> <div class="row"> <label class="col-lg-6" for="username">Username</label> <input type="text" maxlength="50" class="form-control col-lg-6" name="username" placeholder="Enter username" value="<?php if (isset($row['username'])) { echo $row['username']; } ?>"> </div> <div class="row"> <label for="password" class="col-lg-12">Password</label> <input type="password" class="form-control col-lg-12" name="password" placeholder="Enter password" value="<?php if (isset($row['password'])) { echo $row['password']; } ?>"> </div> <div class="row"> <label for="confirmPassword" class="col-lg-12">Confirm Password</label> <input type="password" class="form-control col-lg-12" name="confirmPassword" placeholder="confirm password" > </div> <div class="row"> <input type="submit" class="btn btn-primary" name="submit" value="update" > </div> </div> </form>
Harsh Kumar
$идентификатор = параметр $_GET['идентификатор'];
установите значение null при нажатии кнопки Обновить. вот почему запрос не выполняется