A
A
alexey_khorin2021-06-21 12:05:29
PHP
alexey_khorin, 2021-06-21 12:05:29

How to fix id data mismatch?

60d055dfe703f396309059.png
in the address bar, the id of the entry being edited (correct), in the id field =1 (incorrect)

if (isset($_GET['id'])) {
    if (!empty($_POST)) {
        $id = isset($_POST['id']) && !empty($_POST['id']) && $_POST['id'] != 'auto' ? $_POST['id'] : NULL;
   $surname = isset($_POST['surname']) ? $_POST['surname'] : '';
    $name = isset($_POST['name']) ? $_POST['name'] : '';
    $patron = isset($_POST['patron']) ? $_POST['patron'] : '';
    $serie = isset($_POST['serie']) ? $_POST['serie'] : '';
    $number = isset($_POST['number']) ? $_POST['number'] : '';
    $propiska = isset($_POST['propiska']) ? $_POST['propiska'] : '';
    $telephone = isset($_POST['telephone']) ? $_POST['telephone'] : '';
    $ls = isset($_POST['ls']) ? $_POST['ls']:'';
    $balance = isset($_POST['balance']) ? $_POST['balance'] : '';
    $date = isset($_POST['date']) ? $_POST['date'] : '';
        // Update the record
        /*CLIENT*/
        $stmt = $pdo->prepare('UPDATE Client SET surname = ?, name = ?, patron = ?, serie = ?, number = ?, propiska=?,telephone=? WHERE id = ?');
        $stmt->execute([$surname, $name, $patron, $serie, $number,$propiska,$telephone, $_GET['id']]);
        /*BANK*/
        $stmt = $pdo->prepare('UPDATE bank SET ls = ?, balance = ? WHERE id = ?');
        $stmt->execute([$ls,$balance, $_GET['id']]);
        header('Location:/read.php');
    }
    // Get  contact from  table
    $stmt = $pdo->prepare('SELECT * FROM Client,bank WHERE Client.id = ?');
    $stmt->execute([$_GET['id']]);
    $contact = $stmt->fetch(PDO::FETCH_ASSOC);
    if (!$contact) {
        exit('Контакт не найден!');
    }
} else {
    exit('Контакт не найден!');
}
?>
<?=template_header('Редактирование')?>

<div class="content update">
    <h2>Обновление записи #<?=$contact['id']?></h2>
    <form action="update.php?id=<?=$contact['id']?>" method="post">
         <label for="surname">id</label>
        <input type="text" name="id" placeholder="id" value="<?=$contact['id']?>" id="id">
        <label for="surname">Фамилия</label>
        <input type="text" name="surname" placeholder="Фамилия" value="<?=$contact['surname']?>" id="surname">
        <label for="name">Имя</label>
        <input type="text" name="name" placeholder="Имя" value="<?=$contact['name']?>" id="name">
        <label for="patron">Отчество</label>

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question