Machina Posted August 4, 2003 Posted August 4, 2003 I'm having a bit o' trouble with getting post variables from a form in a php script. Basically i've got a search form that allows users to search a stock list, but the php script doesn't seem to be able to get the post variables. The form code is: <form name='form1' method='POST" action='index.php?action=search'> The bit that isn't working in the php script is essentially: if($HTTP_GET_VARS['action'] == "search") { global $HTTP_POST_VARS; echo $HTTP_POST_VARS['searcharg']; } I've tried loads of variations of this but nothing ever shows up. I'd appreciate any help anyone can give on this, it's really driving my screwy and you know that in the end it's gonna turn out to be something really straight forward. Thanks guys Quote
surefire Posted August 4, 2003 Posted August 4, 2003 Somewhere near the top of your script, I would suggest going through all of the variables and assigning them like so: $name = $_POST['name'];$email = $_POST['email']; and so on for your variables. If you have twenty, then you'll need to assign twenty variables. This is the method I use. There might be a better way... but I haven't come across it yet. Also, I would encourage you to remove the action=search from your url and instead pass the variable as a hidden tag in your form. Then it becomes a part of the data posted to the script and you can get the value by: $action = $_POST['action']; Hope this helps. Quote
raDeon Posted August 5, 2003 Posted August 5, 2003 Somewhere near the top of your script, I would suggest going through all of the variables and assigning them like so: $name = $_POST['name']; $email = $_POST['email']; and so on for your variables. If you have twenty, then you'll need to assign twenty variables. This is the method I use. There might be a better way... but I haven't come across it yet. Here is the better way: At the top of the script (or where you need it), put >extract($_POST); That will automatically convert >$_POST["blah"] to >$blah Quote
Machina Posted August 5, 2003 Author Posted August 5, 2003 Hmm, well I've found the source of the problem (kinda). What you guys suggested works right up until I create an instance of the phplib Session class. It seems that once I do that the global variables are completely wiped so I can't access them (unfortunately I do need access to them after the session is started). I've tried copying $_POST into a new array right at the beginning of the script but that seems to be wiped as well. Even if I do extract($_POST) the variables that are created have no contents. This is so screwy, does anyone have any knowledge of phplib and perhaps why this would be happening? Thanks a lot Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.