Jump to content

Passing Variable From Php To Html And Back Again


dinita

Recommended Posts

I have a question about passing a variable from php to html and back again

 

 

Ideally i'd like to pass a customers name inputted into php file using a form out into the form submission page as a hidden form input and then use this value in a new php file when a button is pressed to send them back to the home page.

 

the aim is to show the users name once they have completed the form. I've had a look around and many people suggest using code similar to this:

value="<?php echo htmlspecialchars($name); ?>"

 

but if i include this in my html form do I not have to save the html document as php?

 

I hope someone can help, thanks in advance!

You cannot use php code if the file does not have a php extension. To use dynamic data in a HTML document would require Javascript to make an ajax call to a server side script.

 

The simplest way to make data persist through multiple pages is to store it in a session. I can then be accessed on any page until it is destroyed.

Hi Neil, thanks for getting back to me I tried this and after clicking the link back to the home page via another php file which just prints the username and then redirects to the home page using the HTTP Header Response, this gives me an undefined variable error.

That's dependent on sever settings. HTML files can be set up to be parsed as PHP. I used to use .haku files as php files!

Yes, but in the general sense HTML (no modification of php.ini, etc.) is static and cannot contain server side code.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.