Foreign dynamic variable in php code file

Hello, my website content mostly depends on code in url (e.g. website?code=jkhy253h) and when I want to edit or something some content, website redirect me to file with php code, and my problem is that php file hasn’t a code in it own url (website/code.php). How can I get this code? In normal I’m using code = _GET[‘code’]. Thanks for answering.

Sorry, I’m having trouble understanding so this is only a best guess:
A problem involving pretty URL routing?

Please try to rephrase as best you can using different words for when “code” has different meanings and be a bit more explicit about what the “this” is and what is not “normal” about what you are wanting to do.

1 Like

I’m sorry for my incomprehensible and chaotic writing. I will try to explain it better.

At my website I can create a subpages. When I’m creating them, a uniqueid is assigned to this subpage. In my case it looks like this:

$uniq = uniqid(); //let's assume that is "123"
//There is some code that is also assigns $uniq to database
header("location: website?d=$uniq"); //This is what I was calling code but it doesn't matter

So I am now at website?d=123
And newly created subpage depends on variable :

$d = $_GET['d']; //"123" from URL
//Here I'm bringing values from database where $d ("123") appears.

Therefore my problem that I was describing in post is when I open my subpage and I want to edit some content, it requires to redirect to php file (website/phpfile) in which code is performing:

  //$d = $_POST['d'];
  $stmt = $conn->prepare("UPDATE data SET name=?, location=? WHERE uniq=$d");
  //some code here
  //header("location: website?code=$d");

But if I am at website/phpfile, there is no $d in URL, and without it I can’t edit my content.

1 Like

Why would you be doing this? What is the real problem you are trying to solve by doing this?

So how do you edit a page? Is there a link on the page that leads to an edit page? If so, can’t you just put d in the URL of the edit page?

I have made a mistake in last line of code should be header(“location: website?d=$d”)

I’m assigning uniqueid to subpages, because I want to create them dynamiclly how much I want, and each of subpages is vary. For example in this forum all topics are the same page (as a file) but each has different numbers in URL and depends of them what content will be shown (at least I think so)

It works like:
<form action"phpfile.php">
In which code is performing, but as I said it have not this $d in URL, which is require to editing because for example I want to edit value from database where $d appears, and then I want to back to website?d=$d
website?d=123 > website/phpfile > and I want back to website?d=123 again.
I would like $d and my php file.

Okay. So make it <form action"phpfile.php?d=<?php echo $_GET['d']; ?>">

1 Like

Ok, this works, thank you very much for help. I wouldn’t think it was that easy.

1 Like