J
J
Jack Daniel's2015-12-14 13:44:39
PHP
Jack Daniel's, 2015-12-14 13:44:39

Why is the form not being submitted using the POST method?

There are two pages: index.php and form.php. On the first (index.php) form, on the second page the data that we entered into the form should be displayed.
Code:
index.php

<form method="post" action="form.php">
 <input type="text" name="username" />
 <input type="submit" id="send" name="submit" value="Отправить" />
</form>

form.php
<?php

 echo $_POST['username'];

?>

Perhaps, of course, complete nonsense is written on the form.php page, but I have already tried many options.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
newpy, 2015-12-14
@newpy

Are you sure that the first file is index.php and is it written correctly? In form.php you specify an opening <?php tag and a closing tag, but in index.php you have no tags. In this case, it should be the index.html file. Or you are not giving the full text of the first index.php file. Or if you want it to be php and interpreted correctly, then it should be
index.php

<?php
echo '<form method="post" action="form.php">
 <input type="text" name="username" />
 <input type="submit" id="send" name="submit" value="Отправить" />
</form>';

Or without <?php ?> tags and rename to index.html
And do you have index.php and form.php files on the same level (in the same folder side by side)
If this doesn’t help, make sure that your interpreter is working properly .

F
Flasher, 2015-12-14
@Flasher

if (isset($_POST["username"]) && !empty($_POST["username"])) {
    echo "Yes, usernameis set";    
}else{  
    echo "N0, username is not set";
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question