I have this url which sends the id parameter through the get method, but when I want to receive it through the controller, it tells me that it does not exist.
http://localhost/course-php/databases/public/list/update/?id=1
public function getUpdate(){
global $pdo;
$id = $_GET['id'];
$sql = "SELECT * FROM users WHERE id=:id";
$query = $pdo->prepare($sql);
$query->execute([
'id' => $id
]);
$row = $query->fetch(\PDO::FETCH_ASSOC);
$nameValue = $row['name'];
$emailValue = $row['email'];
return render('../views/admin/update.php', ['nameValue'=>$nameValue, 'emailValue'=>$emailValue]);
}
Then this throws me
Notice: Undefined index: id in /opt/lampp/htdocs/curso-php/databases/app/control/admin/usersControl.php on line 21
If you use Symfony here is what you need: https://symfony.com/doc/3.4/introduction/http_fundamentals.html#symfony-request-object
If you use Laravel: https://laravel.com/docs/5.6/requests
If you want to receive parameters, think of the browser as making a request to the server. That is a request.
Anyway, in order to collect the id of a pretty url you need to declare it in the Routing and pass the id as a parameter to the function.
https://symfony.com/doc/current/routing.html - If you don't do it with any framework, use var_dump($_GET) to have it returned
if you do this on the page where the form is
And this one on the receiving page:
It should work now what I don't understand is if you put Ñ or á or é or í because it doesn't work if you have the metacharset in uft-8 or as it is my case that in the URL the name with special characters is already wrong, let's see If someone clears it up for me.