Jump to content

how to get input from html and display output in php


gaya

Recommended Posts

Hi, I am learning php newly. I see some examples containing .html file for getting input and .php file for getting output. I cant understand this. please any1 explain this how to do this, and y we r doing like this.please :)

Link to comment
Share on other sites

html is markup language which is used to format the page. it is not programming language so it cant to do any calculation. when we see page in browser it is responsible by HTML but when we send data to form and process it server side language like php is used. Form processing has invovlvement with calculation and logical desciions so it needs to handle by programming lanuage. .html is for html file and .php is for php file. by default .html file can not be executed as php flle. You can serve static html file to show up data and then process it in php file but only when you dont need to show any dynamic content in first place. When we use php to show html page it just interpreted by php and it outputs html. so if static html is used it can reduce overhead of php interpretion where it is not needed

  • Like 1
Link to comment
Share on other sites

Thanks Birbal.Also please tell me,Might b my question is silly, but i dnt knw, tats y i'm asking.please tell me ,the following is the sample code welcome.html

<html><body><form action="welcome.php" method="post">Name: <input type="text" name="fname">Age: <input type="text" name="age"><input type="submit"></form></body></html>

welcome.php

<html><body>Welcome <?php echo $_POST["fname"]; ?>!<br>You are <?php echo $_POST["age"]; ?> years old.</body></html>

whether both should get saved in htdocs folder only or else the .php alone should be saved in htdocs folder.Also please tell me how to execute this. :) please.

Link to comment
Share on other sites

htdocs is your web root. php file will (commonly) only be executed through web server. thats happens when we use localhost to get pages from web root. if you try to open it using file system it will be shown as plain text. but as html files are not dependent on web server to get interprete it dont need to be in web root to see it properly. if you use filesystem to open the file in browser the text will be interpreted as html and will show it in browser. but if you want to be publicaly available you need to put it in web root. usually both are being saved in web root.

  • Like 1
Link to comment
Share on other sites

For now, just make sure all files are in the webroot, especially HTML files since this is how they are made publically avaialable to yourself and other users (if and when they are uploaded to a server). However, the location of the files is important when it comes to how one file references the other in. in the case of your welcome.html, the form action is welcome.php, so you are defining the location of welcome.php to be in the same folder as the html file. If you want to move one file relative to the other, then you have to make the appropriate changes. For example, if you wanted to put welcome.php in a folder called php-scripts, (which is located in htdocs) then your form action would need to look something like this

<form action="php-scripts/welcome.php" method="post">

Edited by thescientist
  • Like 1
Link to comment
Share on other sites

Thanks Birbal and Thescientist for sharing me the useful and helpful replies. :)Another thing is when connecting to localhost"http://localhost/phpmyadmin/" it is showing lik tisWrong permissions on configuration file, should not be world writable!Why it is showing lik tis. please tell me. whether anything i've entered might b wrong. :)

Link to comment
Share on other sites

I solve the Wrong permissions on configuration file, should not be world writable! pbm.please tell me, how to insert the values in database through texbox. While clicking submit the thing what i have entered is to be seen into my database.How shall i do this.please tell me :)

Link to comment
Share on other sites

have you done through any of the PHP tutorials at all? This kind of stuff is covered, and would be faster than asking and waiting for a reply.http://www.w3schools.com/php/php_forms.asphttp://www.w3schools.com/php/php_mysql_intro.asp

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...