How to pass a value from php to html?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
shishirkotkar
Forum Newbie
Posts: 1
Joined: Sat Apr 17, 2010 9:12 am

How to pass a value from php to html?

Post by shishirkotkar »

I have a html file - Home.html
I have another php file - test.php

I am calling test.php on click of a submit button from Home.php

in test.php i am processing the input data entered from Home.php

I want to send the processed results back to Home.php and present it as values in dropdown list.

How do i do that?
User avatar
JAY6390
Forum Newbie
Posts: 20
Joined: Sat Apr 17, 2010 6:51 am
Location: UK

Re: How to pass a value from php to html?

Post by JAY6390 »

I would suggest you do this with one page like I show in the following URL
http://www.jaygilford.com/php/how-to-pr ... -one-page/

You can redirect to the page using the header() function and the Location value, but would still need to send the data with it (using something like a session of some sort). You would need to change home.html to home.php to get this to work correctly or use some htaccess rewrites to get it to work with php
st3fanos
Forum Newbie
Posts: 12
Joined: Tue Apr 13, 2010 1:30 am

Re: How to pass a value from php to html?

Post by st3fanos »

Hi,

First I am going to assume you have home.html and test.php (not home.php) and for some reason you cannot change the name of home.html.

You can do what you want by using the GET method, i.e your URL back to your home.html from test.php would look like http://www.somedomain.com/home.html?var ... var2=World

You can then go ahead and do something like the following using javascript:
http://failchad.blogspot.com/2009/01/ac ... cript.html

But why?
1) If it's a problem that you cannot process the HTML file as PHP code you could use the .htaccess and tell your server to treat the .html as if it were PHP.
or
2) change the filename home.html -> home.php and use mod_rewrite so it looks like home.html (not sure of the top of my head the code)

With all the above methods the end URL looks like home.html, but with the last 2 you can avoid passing the values in the URL.

Hope it helps
Stephen
Post Reply