Page 1 of 1
Transfering a variable to the next site
Posted: Sat Mar 26, 2005 10:01 am
by frANZi
Hello !!!
This is my problem. I need to transfer the variable $var, when I click "SUBMIT" in the form, from the index.php site to the submit.php site and I want to access the variable with the $_POST function or with something else.
Any ideas how to do this. It is probably simple, but I don't know it.
Thanks, anyway.
Posted: Sat Mar 26, 2005 10:10 am
by thallish
hey
all you have to do is to give whatever your input is a name and then access it through $_POST['name']
like this:
this is your index.php
Code: Select all
<form action="e;submit.php"e; method="e;post"e;>
<input type="e;text"e; name="e;foo"e; />
<input type="e;submit"e; value="e;button"e; />
</form>
Now in yout php code you do following to access it
To write out your POST-array to see what it contains do
regards thallish
edit: just edditted the code for index.php. Now it's like it should be

Posted: Sat Mar 26, 2005 10:15 am
by feyd
maybe you mean transferring this variable to the next page on your site? thallish's post just about sums it up, but to use $_POST, you must specify method="post" in your form.
Posted: Sat Mar 26, 2005 3:23 pm
by frANZi
Wooow, but this wasn't my question. I know how to do this with a variable that I type in a textbox, but when I specify the variable just so: $var = 1, what then ???
Posted: Sat Mar 26, 2005 3:24 pm
by feyd
that'd depend on what you really want to do and how you are using the code you want to send the variable to..
Posted: Sun Mar 27, 2005 7:12 am
by frANZi
I don't know how to explain that... O.K. On index.php in my php code I have specified the variable $var = "blablabla". That variable musn't be "blablabla", it can be anything else. Now, when I click "Submit" in my form (form's action is next.php), I want read the variable in next.php. How can I do it so???
Thanks.
Posted: Sun Mar 27, 2005 7:41 am
by anjanesh
So you want to use your variables internally ?
You can use session variables (
http://www.php.net/manual/en/ref.session.php) - but this will ultimately store it in your server's file or database (which ever way you use sessions).
Each script you run will be like a brand new script - whatever variables you want passed accross will either be through GET, POST, media storage (files or database), SESSIONS (ultimately media storage).
When I started coding in PHP I too thought I could store some variables in some location in some global RAM or something.
Web languages will not have the flexibility of C/C++ due to security etc.
But I understand in C# some tweaking like this can be done ?
Posted: Sun Mar 27, 2005 8:14 am
by frANZi
OK, ok... I don't want to use sessions or something like that. I know it can be done by placing a hidden field in index.php and later I can access the variable by $_POST.
But is this safe??? I uploaded the file on my localhost server, and then I saved index.php on my hard disk. Then I opened the file in Dreamweaver and in the value of input was $var.
Posted: Sun Mar 27, 2005 9:45 am
by anjanesh
Oh. Frankly, I dont know what Dreamweaver will do to php code. May be its showing the variable name ?
Check it using any simple text editor (like Context :
http://www.context.cx)
Do a echo $_POST['hiddenValue'];
$_POST cannot be considered safe - anybody can change the html code and have the input hidden field change its value. Should be used only for client side interaction.