E
E
evgeniupjhp2020-01-02 17:25:41
PHP
evgeniupjhp, 2020-01-02 17:25:41

How to change data from sql database by seeing the data?

Hello everyone, here is the code:

if(isset($_POST['save'])) {

  $sql = "UPDATE `users` SET
          `qyes` = '".mysqli_real_escape_string($link, $_POST['qyes'])."',
          `answer` = '".mysqli_real_escape_string($link, $_POST['answer'])."',
          `value` = '".mysqli_real_escape_string($link, $_POST['value'])."',
          `status` = '".mysqli_real_escape_string($link, $_POST['status'])."'
          WHERE `id` = '".$_POST['id']."';";

  if(mysqli_query($link, $sql)) {

    $info = "Сохранено";

  }

}


I need inputs that already have data from the database, that is, I open a link with all this, there are not empty fields, but input fields that already have this data (from the database), and I just change them, I press the save button and it is updated in the database. How to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Sokolov, 2020-01-02
@sergiks

Usually use ORM. Simply put, an object that represents a record in a table.
First, it is loaded from the database: and shown in the form:$record = User::find(123);

return view('user-form', ['user' => $record->toArray()]);

When you save, you get incl. idedited record, and under it save the received data.
Google php CRUD

M
Mors Clamor, 2020-01-02
@66demon666

Tyk

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question