1

I started with HTML yesterday and I'm trying to send some data from a page to another using PHP. I don't know if I am missing something but even the code I found on the Internet isn't working for me.

This is the code of my form:

<div class="login"> <form name="myForm" action="post.php" method="POST"> <div class="group1"> <input type="text" name="fusername"><span class="bar"></span> <label>Username</label> </div> <div class="group2"> <input type="text" name="fpassword"><span class="bar"></span> <span class="password"></span> <label>Password</label> </div> <button type="submit" class="button buttonBlue">Login</button> </form> </div> 

while this is the overall code of the post.php page:

<html> <body> Welcome <?php echo $_POST["fusername"]; ?><br> You inserted as a password: <?php echo $_POST["fpassword"]; ?> </body> </html> 

The only things I see after clicking the "Login" button are "Welcome" and "You inserted as a password".

I tried both get and post methods (with consistency) and I am still not able to see what I inserted in the forms.

I even tried to print a simple hello word, modifying the post.php page in this way:

<html> <body> <?php Echo "Hello, World!"; ?> </body> </html> 

but doing that I get a white page.

What am I actually missing or misunderstanding?

Many thanks.

12
  • 1
    Your method is POST and you are using $_GET. Change it to $_POST. Commented Aug 4, 2017 at 8:44
  • Sorry, that was a typo, I tried both get and post with consistency but I still got the same problem. Commented Aug 4, 2017 at 8:51
  • Check error by var_dump($_POST). Tell us what you get an error? Commented Aug 4, 2017 at 8:53
  • Just for kicks, get rid of this part in the <form> tag and try again: onsubmit="return validateForm()" Commented Aug 4, 2017 at 8:54
  • I tried getting rid of that part but still no results. Commented Aug 4, 2017 at 9:00

4 Answers 4

0

Change GET to POST. GET and POST are two different methods. You have to be consistent on how to use them in your forms. Personally, I prefer to always use POST unless there's a good reason to use get.

<html> <body> Welcome <?php echo $_POST["fusername"]; ?><br> You inserted as a password: <?php echo $_POST["fpassword"]; ?> </body> </html> 
Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, that was a typo, I tried both get and post with consistency but I still got the same problem.
0

Remove onsubmit="return validateForm()" from Form because your action of your form is already given so no need of validation then.

if it work then ok but if not then set action with full path like("http//www.example.com/post.php").

1 Comment

Tried both things and still with the problem. I update the question in a sec
0

Please check you form as per this link

https://www.w3schools.com/html/tryit.asp?filename=tryhtml_form_submit_id

This is working fine as per your problem ..

You need to just change html with your input name .

Comments

0

Maybe you don't have php on server side

write

<?php phpinfo(); 

and run it

1 Comment

Sorry mate, that was a typo. Of course I tried things with consistency and I still got the same problem

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.