How to _POST a variable?
I have a form which posts things like the users name and stuff. But how do I post my own stuff over to the next page without having to create a textfield/etc?
Something like: $_POST['myVariable'] = 'This is what I want to send to the next page'
Which of course will be invisible to the user, but when they click submit, not only will the users name etc get posted, but I can also receive the 'myVariable'?
You'll have to use an input field no matter what. You'll just make the input field invisible to the user.
Then you'll use $_GET $_POST or whatever to get the info.
<input type="hidden" name="input" value="info you want to submit">
This question is borderline PHP. So you might want to ask to have it moved if you plan to discuss PHP related aspects.
Of course if the info you are wanting to submit is always going to be the same, a timestamp, or some kind of php function, etc you could set up a variable in your PHP page.
$myinfo = "blah";
The predefined $_POST variable is used to collect values from a form sent with method="post".
Information sent from a form with the POST method is invisible to others and has no limits on the amount of information to send.
Note: However, there is an 8 Mb max size for the POST method, by default (can be changed by setting the post_max_size in the php.ini file).
It depends on what John is trying to send. If the information is something that has to do with the user filling out the form then he'll want to use a hidden input field. However, if whatever information John is collecting doesn't have to come from the form it should be stored as a variable in his PHP code.
This being said. John, what kind of information are you trying to collect?
I'm just trying to send strings to tell the next page what to do.
This is just a spammer (recognizable by the completely unrelated spam link at the end of the post – which I’ve removed) and you shouldn’t copy their spam links by quoting their entire posts. However, since the info in the post sounds fairly accurate to me (as non-back-end developer) I’m gonna leave it there for now.
Originally Posted by stevenmw
There is also the $_SESSION variable that stores values in the users session until they close the browser. So it would stick between pages.
You start a session by calling the session_start() function
Then store stuff like $_SESSION['name'] = 'Johnson';
now an any page that has session_start() in it you can access $_SESSION['name']
That sounds like a nice idea, but how do I attach the $_SESSION code to the link that opens the window? Sorry I'm a newb..
Originally Posted by Truffle
If you just want to post a variable to a DB you don't have to use a session.
Obviously this needs to be cleaned up, and needs a few improvements. But it shows you don't need a session for simply posting a variable.
$first = $_POST['firstname'];
$last = $_POST['lastname'];
$var = "you variable";
$con = mysql_connect("localhost","user","pass");
die('Could not connect: ' . mysql_error());
mysql_query("INSERT INTO table (first, last, var)
VALUES ('$first', '$last','$var')");