Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Variables in another Page

Status
Not open for further replies.

M2E

IS-IT--Management
Aug 1, 2005
28
0
0
GB
Hi there,

Would like to know how (if possible) can I update a variable which I have created in another page?

for example in main.php i create a variable called $song
then in main2.php i am able to enter in a value and then update $song with this value?

Can this be done, or will I have to use it with a database?

Thanks in advance!!!

----Ment2Excel (M2E)----
--LEARN BY EXAMPLE--
 
Hi,
Have you thought about putting the value into a Cookie so that it can be accessed from any of your pages?

M [wiggle]
 
Unless you send the variable $song from main.php, into main2.php by means of a form and a submit button or sending it in the URL for main2.php, doing $song="somesong"; in another page will result in the creation of a new variable, $song for that page.

Example:
Code:
<form action=main2.php method=post>
<input type=hidden name=song value="somesong">
<input type=submit>
</form>

or

Code:
<a href="main2.php?song=somesong">

These two methods will send a variable into main2.php.
You see variables in PHP are not global in scope unless set in cookies as Mthales said. Otherwise, $song in main2.php will not contain any information that $song in main.php had.
 
If I understand you right, you will have two pages. Page 1 being the main page which loads first and has a field or some other type of place holder for $song. Page 2, which loads after Page 1 will give the user the ability to enter the song.

Now, if you would just like to relaunch Page 1 with the song displayed, all you would need is a link from Page 2 that calls page 1 again. Something like the following would work just fine:

Code:
In main2.php
<a href="main1.php?$song=songname>Submit Song</a>

If, on the other hand, you do not want to load main1 again but just want to have the field automatically uploaded, my experience has been to use something like javascript. With javascript, you can launch the new window and maintain a reference to a field from a form on the first page. Then, based on the value entered in main2, it can update the value in main1.php. I've used this in the past to create a pop-up calendar to allow users to select a date and then forward that date back into the form field on page 1. Everything except the variable forwarding can be done with php.

Remember that php is a server side scripting language. As a result, you can't really touch the page with php after it has been sent to the client. Your only chance to modify it with the php is on loading...as far as I know.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top