AndrB AndrB - 8 months ago 19
MySQL Question

undefined index id.. PHP

I'm trying to delete some data from a table in a mysqli database, and I receive that error. I tried with isset, writing it directly without using a variable, nothing works. What am I doing wrong?



$link = mysqli_connect("localhost", "root", "", "documents");

if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());

$ID = $_POST['id'];

$result = mysqli_query($link, "DELETE FROM document WHERE id='$ID'");

header("Location: connect-db.php");


If you are fetching id from URL then use

$ID =isset( $_REQUEST['id']) ? $_REQUEST['id'] : 0; 


$ID =isset( $_GET['id']) ? $_GET['id'] : 0;

If you are fetching id from POST variables then use

$ID =isset( $_POST['id']) ? $_POST['id'] : 0;