0

I'm trying to handle a form that updates some data in a postgreSQL table. To do that, I GET the id for the item to update. The URL reads:

[...]pojazd.php?id=1[...], which successfully GETs the data.

Then I want to store it in a session (that was opened before):

$_SESSION['id'] = $_GET['id'];
$id = $_SESSION['id']; 

When I use my $id variable to SELECT the data, it works fine.

SELECT model, cena FROM pojazd WHERE id_poj = $id" does the job.

But when I want to update this data using a POST form:

if (isset($_POST['update'])){
[...]
UPDATE pojazd SET model = '$model', cena = '$cena' WHERE id_poj = $id;
}

nothing happens. When the $id variable is hardcoded (for example: replaced by 1 etc), it works fine. But the $id variable seems to unset itself whenever the form is POSTed. I tried echo'ing the $id variable whilst disabling the redirecting, and that's exactly what happens - the $id variable disappears.

I'm at a loss. The clock is ticking, I really don't want to fail my class, but that problems ruins my entire project...

1 Answer 1

1

You need to replace

$_SESSION['id'] = $_GET['id'];

with

if (isset($_GET['id'])) $_SESSION['id'] = $_GET['id'];

so that the value doesn't get overwritten with an empty value when the form is POSTed...

Sign up to request clarification or add additional context in comments.

1 Comment

Such a stupid mistake... I panicked and stopped thinking logically. Thank you <3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.