C
C
counterprowtf2018-11-30 19:40:40
PHP
counterprowtf, 2018-11-30 19:40:40

How to update the data received from the form?

I know about UPDATE, I don’t know how to correctly write a query to the database
Probably a very stupid question, but I want to update the data in the profile, I can’t understand why it doesn’t update the record in the database, I’m new to php, the request may be wrong, please help, sorry for stupid question, thanks in advance

<?php
if (isset($_POST['upload_info'])) {
  $db = mysqli_connect('localhost', 'root', '', 'profile');

  $fio = $_POST['fio'];
  $status = $_POST['status'];
  $city = $_POST['city'];
  $birthday = $_POST['birthday'];

  $sql = "INSERT INTO info_users (fio, status, city, birthday) VALUES ('$fio', '$status', '$city', '$birthday')";

  $update = "UPDATE info_users SET fio = '$fio' SET status = '$status', SET city = '$city', SET birthday = '$birthday' WHERE id = 1 ";


  mysqli_query($db, $sql, $update);
  header('Location: profile.php');

}

this is edit.php
<h1>Редактировать</h1><br>
  <form action="edit.php" method="post">
    <p>
      <input type="text" name="fio" placeholder="ФИО">
    </p>
    <p>
      <input type="text" name="status" placeholder="Статус">
    </p>
    <p>
      <input type="text" name="city" placeholder="Город">
    </p>
    <p>
      <input type="text" name="birthday" placeholder="День Рождение">
    </p>
    <button type="submit" name="change_info">Изменить</button>
  </form>

  <a href="index.php">Вернуть в профиль</a>

this is a form in which you enter values ​​and they should be updated in the database and displayed
here5c01697f2dbb2239627273.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Antony Tkachenko, 2018-12-01
@LemonFox

Here you have something clearly wrong:
php.net/manual/ru/function.mysql-query.php
Most likely it meant
Well, UPDATE itself
Well, the mysql_* functions have long been marked as deprecated and are no longer supported. So their use is not safe. Use mysqli_* analogues (fortunately they are backwards compatible and can be made a replacement).
Better yet, use PDO + prepared
statements php.net/manual/ru/book.pdo.php
php.net/manual/ru/pdo.prepared-statements.php

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question