Answer the question
In order to leave comments, you need to log in
Data is not transmitted by the POST method, how to fix it?
Goodnight!
I can not understand the essence of the problem. There is an Apache + Nginx + php5.6 server, there is a simple script:
<?php
if ($_GET['ok']==''){
echo "<form action='?ok=ok' method='post'>
<input type='text' name='login' placeholder='Логин'><br>
<input type='text' name='password' placeholder='Пароль'><br>
<input type='submit' value='OK'><br>
</form>";
}else{
echo $_POST['login'];
}
?>
$postdata = file_get_contents("php://input");
$postdata=explode('&', $postdata);
foreach ($postdata as $k=>$v){
$v=explode('=', $v);
$_POST[$v[0]]=urldecode($v[1]);
}
Answer the question
In order to leave comments, you need to log in
Good evening.
The first line, always, forever - error_reporting(E_ALL);
Turn on the output of all errors that are possible.
And then start writing code!
Set the action attribute to a value if the form and the handler are in the same file, then just try #
In the if ($_GET['ok']=='') or if ($_POST['ok']=='') line there will be a warning , because such arrays do not exist initially. Only after submitting the form can you receive any of them.
if(isset($_POST)){
// делаем что-то
}
else{
// выводим форму
}
Do this:
<?php
if ($_POST['ok']==''){
echo "<form action='?' method='post'>
<input type='hidden' name='ok' value='ok'>
<input type='text' name='login' placeholder='Логин'><br>
<input type='text' name='password' placeholder='Пароль'><br>
<input type='submit' value='OK'><br>
</form>";
}else{
echo $_POST['login'];
}
?>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question