In general, this task: the first time you run the page $id empty. So let me press submit, the data is written to the database, and $id = $row[0]; will be equal to the value. If I press submit again, the isset($id) condition is not met. Where is the mistake? Maybe somehow it is implemented differently?

  • Throw an example? - sitev_ru

2 answers 2

This is done like this.

  <?php session_start(); if(isset($_SESSION['id'])) { echo $_SESSION['id']; } else { $_SESSION['id'] = $row[0]; } 
  • If there are several pages with different id, then: 1. A person in one browser will be able to view only one page with id. 2. It is necessary to provide for the cleaning of the id from the session (if necessary). - IVsevolod
  • Yes, this is editing the passport, and you can run only one at a time. It more than suits me. And about unset ($ _ SESSION ['id']); when returning to the main page I know. Not the first day married. - anunak

As I understand it, $ id is passed to <input type="hidden" name="id" value="<?= $id ?>" > ?

In this case, you can check for empty:

 $id = $_POST['id']; if (empty($id)) { // Если $id пустой. } 
  • <input type = "hidden" name = "id" value = "<? = ($ id)? $ id: ''?>"> just in case - MrGaliev
  • Empty from void will be true $ id = ""; empty ($ id) // true - IVsevolod
  • And so there may be an error on the non-existence of a variable. Or check if (! $ Id) - MrGaliev
  • <input type = "hidden" name = "id" value = "<? = ($ id)? $ id: ''?>"> and what does this do? - anunak