Jump to content

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.

Edited by dinita

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.