Post Variables

liunx

Guest
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:<br /><br /><form name='form1' method='POST" action='index.php?action=search'><br /><br />The bit that isn't working in the php script is essentially:<br /><br /> if($HTTP_GET_VARS['action'] == "search")<br /> { <br /> global $HTTP_POST_VARS;<br /> echo $HTTP_POST_VARS['searcharg'];<br /> }<br /><br /><br /> I've tried loads of variations of this but nothing ever shows up.<br /><br />I'd appreciate any help anyone can give on this, it's really driving my screwy<br />and you know that in the end it's gonna turn out to be something really straight<br />forward.<br /><br />Thanks guys <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
Somewhere near the top of your script, I would suggest going through all of the variables and assigning them like so:<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec-->$name = $_POST['name'];<br />$email = $_POST['email'];<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />and so on for your variables. If you have twenty, then you'll need to assign twenty variables.<br /><br />This is the method I use. There might be a better way... but I haven't come across it yet.<br /><br />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:<br /><br />$action = $_POST['action'];<br /><br />Hope this helps.<!--content-->
<!--QuoteBegin-surefire+Aug 4 2003, 03:53 PM--><div class='quotetop'>QUOTE(surefire @ Aug 4 2003, 03:53 PM)</div><div class='quotemain'><!--QuoteEBegin-->Somewhere near the top of your script, I would suggest going through all of the variables and assigning them like so:<br /><br /><!--quoteo--><div class='quotetop'>QUOTE</div><div class='quotemain'><!--quotec--><br />$name = $_POST['name'];<br />$email = $_POST['email'];<!--QuoteEnd--></div><!--QuoteEEnd--><br /><br />and so on for your variables. If you have twenty, then you'll need to assign twenty variables.<br /><br />This is the method I use. There might be a better way... but I haven't come across it yet. <!--QuoteEnd--></div><!--QuoteEEnd--><br />Here is the better way:<br /><br />At the top of the script (or where you need it), put<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->extract($_POST);<!--c2--></div><!--ec2--><br />That will automatically convert<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$_POST["blah"]<!--c2--></div><!--ec2--><br />to<br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1-->$blah<!--c2--></div><!--ec2--><!--content-->
Great, thanks guys <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><!--content-->
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<br />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? <img src="http://www.totalchoicehosting.com/forums/style_emoticons/default/smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" /><br /><br />Thanks a lot<!--content-->
 
Top