0

I learn coding in my free time and I tried creating HTML website referring to PHP file. I know that similar problem was discussed here already, but I am NOT using Apache or something and I am beginner, so I did not really understand that answers - can you anyone explain more easy way?

This is my HTML code:

     <form action = "prihlaseni.php" method = "POST" >
      <input type = "text" name= "uzivatel" placeholder = "uzivatelske jmeno">
      <br>
      <input type = "password" name= "heslo" placeholder = "heslo">
      <br>
      <button type = "submit">PRIHLASIT</button>
      <br>
      </form>

I read that it should call the PHP file and execute code in it. Here is my PHP file:

<?php
 $uzivatel  = $_POST['uzivatel'];
 $heslo  = $_POST['heslo'];
 echo $uzivatel;
 echo $heslo;
?>

I thought that the website will show the text called "uzivatel" and "heslo", but it shows the code (up here) as a plain text. I am enclosing a picture of it:

enter image description here

Would you explain me why, someone?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
RDK
  • 71
  • 8
  • You need a web server and the PHP interpreter. The browser show you what it loaded from disk, it doesn't know how to run the PHP code. – axiac Jul 29 '17 at 14:04
  • Hello, thank you very much for your answer. As I said, I am total begginer. I thought that if I put html and php file in the same folder then it works like html + css / js. It doesnt? Sorry if I sound really silly ;) – RDK Jul 29 '17 at 14:13
  • @Radek ... Check This ... : http://phpfiddle.org/main/code/0xvt-4qfc – RïshïKêsh Kümar Jul 29 '17 at 14:14
  • @Radek . if You are beginner then follow this tutorial its help you to learn :: https://www.w3schools.com/php/ .... – RïshïKêsh Kümar Jul 29 '17 at 14:16
  • @RïshïKêshKümar Woah, it works! Thank you so much. But, please, what does "if(isset($_POST['submit']) && !empty($_POST['uzivatel']) && !empty($_POST['heslo']) ){" mean? I dont want to copy paste thing I dont understand.. Can you explain really quick how does it solve the issue and what does it mean? Also, thank you so much for your help. I wish you really happy life. – RDK Jul 29 '17 at 14:18
  • @Radek .. Don't jump to the code direct first start from the basic things .. if want to know what i actually did here before that you have to learn the basic thing from the https://www.w3schools.com/php/ ... After than you easily understand what is going here... – RïshïKêsh Kümar Jul 29 '17 at 14:21
  • @Radek... `if(isset($_POST['submit']) && !empty($_POST['uzivatel']) && !empty($_POST['heslo']) ){ //code of your echo to data }` .. Here actually .... first one if condition i checked that submit button is acutally press or means its set or not , if its set then use `AND` & `&&` to check another 2 more fields `uzivatel` and `heslo` are not empty `! Means (not)` then in side that if i `echo` the your `Post` request data. – RïshïKêsh Kümar Jul 29 '17 at 14:27
  • @RïshïKêshKümar ok, thanks, I will go through the tutorial... ;) – RDK Jul 29 '17 at 14:29
  • @Radek .. Yupp its easy just try it your self :) – RïshïKêsh Kümar Jul 29 '17 at 14:30
  • Alright, thanks. i will go see the tutorial now. Thanks a lot for all your help. I guess that teher was simply something important missing in my code... have a nice day – RDK Jul 29 '17 at 14:32

0 Answers0