I am working on a task and have set up my code as follows:
On index.php
I include a file, which serves as a view with the code:
include 'Controller/CallArticleData.php';
$i = count($display) - 1;
while ($i >= 0) {
echo "<a href='index.php?editID=" . $display[$i]['ID'] . "'>" . $display[$i]['title'] . "</a><br/>";
$i--;
}
Basically, I call the controller, which calls the relevant model and then I use the data to setup the URL - I want it to set $_POST['editID']
whenever a user clicks on the respective link.
However, the variable still remains unset upon hitting the link, even though the URL changes to index.php?editID=12345
. I performed this check both in index.php and in the respective view.
What am I doing wrong?
You need to use $_GET
to access querystring parameters:
$_POST['editID']
should be
$_GET['editID']
$_GET
variables come from the query string. $_POST
variables come from submitting forms with action="post").
Try changing
$_POST['editID']
to
$_GET['editID']
Try to use $_GET['editID']
instead of $_POST['editID']
Info about:
GET - Requests data from a specified resource
POST - Submits data to be processed to a specified resource
The GET Method: $_GET
Note that query strings (name/value pairs) is sent in the URL of a GET request.
filename?name1=value1&name2=value2
The POST Method: $_POST
Note that query strings (name/value pairs) is sent in the HTTP message body of a POST request.
You can either use get or request instead of post
$_GET['editID']; or $_REQUEST['editID'];