'Show connection die, but still able to show the id on the url link

I'm new to the php programming and try to using the sql update query to update my inventories list, but someting gone wrong and show the error.

enter image description here

Dont have any idea why the url successfully shows the inventory ID but at the same time showing the "die". In here, the die referred to "connection die"

Below is the code I wrote for when user clicks edit button, it will go to "page-it-peripherals-update.php"

<form action="page-it-peripherals-update.php" method="POST">
<input type="hidden" name="edit-id" value="<?php echo $Iid ?>" />
<button name="edit" type="submit">Edit</button>
</form>

Below is the code I wrote try get the details of the selected inventory ID under the page called "page-it-peripherals-update.php"

  <?php
   if(isset($_POST['edit']))
     {
      $Iid = $_POST['edit-id'];
      $url = "http://localhost/inventory/page-it-peripherals-update.php?id=".$Iid;
      header("Location: {$url}");
     }else{
      echo 'die';
     }
 ?>

The problem is am I successfully get the inforamtion of the item details and how come it is also showing the else "die" at the same time?

php


Solution 1:[1]

---- CODE EXPLAIN ----

At the first click on the button edit on the first page home or index whatever

You are redirection to the page page-it-peripherals-update.php

Now at the page your $_POST should containt something like that

$_POST = {
    'edit-id' : 'some_val_here',
    'edit'    : true
}

the script from page-it-peripherals-update.php

  <?php
   if(isset($_POST['edit'])) // <-- ho i my $_POST['edit'] is define
     {
      $Iid = $_POST['edit-id']; 
      $url = "http://localhost/inventory/page-it-peripherals-update.php?id=".$Iid; // make new url
      header("Location: {$url}"); // script : ho , let me relocation to the new page 
     }else{
      echo 'die';
     }
 ?>

And you call page-it-peripherals-update.php without any values define

Now at the page your $_POST should containt something like that

$_POST = { }

script :

  <?php
   if(isset($_POST['edit'])) // <-- ho i my $_POST['edit'] isn't define !
     {
      $Iid = $_POST['edit-id']; 
      $url = "http://localhost/inventory/page-it-peripherals-update.php?id=".$Iid; // make new url
      header("Location: {$url}");
     }else{
      echo 'die'; // print 'die'
     }
 ?>

---- comment ----

It dependat what resultat you want if u wont get redirected you should remove the header("Location: {$url}");

Or you can add on extra condition isset($_REQUEST['edit-id']) for if edit-id is define at the url or not

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1