Error when moving variable to another page [duplicate]

On one page I have this button:

<a href="add_purchase_detail.php?purchase_id=<?php echo (int)$id_purchase; ?>" class="btn btn-primary">Agregar producto</a>

And on the landing page I pick it up like this:

$id_purchase=$_GET["purchase_id"];

But he doesn’t admit it to me:

Warning: Trying to access array offset on value of type bool in C:xampphtdocssistemaincludessql.php on line 133

Warning: Undefined array key “purchase_id” in C:xampphtdocssistemaadd_purchase_detail.php on line 5

Fatal error: Uncaught mysqli_sql_exception: Cannot add or update a child row: a foreign key constraint fails (sistema.purchase_details, CONSTRAINT purchase_details_ibfk_1 FOREIGN KEY (purchase_id) REFERENCES purchases (id) ON DELETE CASCADE ON UPDATE CASCADE) in C:xampphtdocssistemaincludesdatabase.php:28 Stack trace: #0 C:xampphtdocssistemaincludesdatabase.php(28): mysqli->query(‘INSERT INTO pur…’) #1 C:xampphtdocssistemaadd_purchase_detail.php(25): MySqli_DB->query(‘INSERT INTO pur…’) #2 {main} thrown in C:xampphtdocssistemaincludesdatabase.php on line 28

I’ve tried request and get, but it’s the same thing.
Also, I don’t know how to fix the problem of the alien key.

By placing this, it no longer tells me that the variable doesn’t exist, but the other errors remain the same:

$id_purchase=isset($_GET['purchase_id']) ? $_GET['purchase_id'] : '';