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.

giovandrea
  • 197
  • 1
  • 4
  • 13

4 Answers4

0

Maybe you don't have php on server side

write

<?php
phpinfo();

and run it

Lesiuk Alexey
  • 237
  • 1
  • 2
  • 7
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>
Virb
  • 1,639
  • 1
  • 16
  • 25
Difster
  • 3,264
  • 2
  • 22
  • 32
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").

baiju jha
  • 463
  • 2
  • 10
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 .

Kuldeep Raj
  • 791
  • 1
  • 7
  • 29