Answer the question
In order to leave comments, you need to log in
Difficulty when working with forms - why are parameters passed via GET lost?
The bottom line is this - I need to do this with the help of a GET request
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<br/>
<form action="" method="GET">
Имя: <input type="text" name="username"><br><br>
<button name="submit">Отправить</button><br><br>
</form>
</body>
</html>
<?php
if (isset($_GET['submit'])) {
echo "Получили GET запрос от " .$_GET['username'];
}
else{
echo "Введите своё имя <br>";
}
?>
Answer the question
In order to leave comments, you need to log in
You need to add type='submit' to the button
Remove action="" Or enter the page to which the submission is being made.
I advise you to put exit(); before the first if and look in the address bar to see if there are get parameters there. If so, then the problem is in your script. Never trust an empty name in a button. You should have at least that. name=submit' value='ok' Then the first if will work. The isset function checks whether the variable is empty, including the get parameter you specified.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question