Page 1 of 1
Extracting variables from form
Posted: Tue Jun 24, 2003 12:50 pm
by JeffElkins
Code: Select all
echo "<b>Calculations</b>";
echo "<form method="post">";
echo "<br>Variable One: <input type="text" name="var1" size="5" maxlength="5">";
echo "<br>Variable Two: <input type="text" name="var2" size="5" maxlength="5">";
echo "<br><br><input type="submit" name="tst"
value="calc">";
echo "</form>";
echo $var1;
echo $var2;
I'm scratching my head here...
I did try:
echo $_POST['variable'];
w/o success.
My eventual goal is some calculations on imputted variables, but the two variables never show up. Obviously a newbie, thanks for any help....
Posted: Tue Jun 24, 2003 1:28 pm
by m@ndio
Hi,
This works fine for me.. are you sure you are trying to use this on a php enabled server?
it could be a bug in your i.e. or something as you have not set your action value in your form.
try this:
Code: Select all
echo "<b>Calculations</b>";
echo "<form method="post" action="whateveryourscriptiscalled.php">";
echo "<br>Variable One: <input type="text" name="var1" size="5" maxlength="5">";
echo "<br>Variable Two: <input type="text" name="var2" size="5" maxlength="5">";
echo "<br><br><input type="submit" name="tst" value="calc">";
echo "</form>";
echo $var1;
echo $var2;
not going to work
Posted: Tue Jun 24, 2003 1:29 pm
by phpScott
as you have your code now $var1 and $var2 will never have values because they are not assigned anything at the moment.
the only way they will have a value is when you submit your form then they will have the value the is stored in there respective html elements.
find some nice simple form submissin tutorials or code snippet and it will help you alot.
phpScott
Posted: Tue Jun 24, 2003 7:49 pm
by DuFF
Code: Select all
<?php
echo "<b>Calculations</b>";
echo "<form method="post" action="$PHP_SELF" METHOD=post enctype="multipart/form-data">";
echo "<br>Variable One: <input type="text" name="var1" size="5" maxlength="5">";
echo "<br>Variable Two: <input type="text" name="var2" size="5" maxlength="5">";
echo "<input type="hidden" name="action" value="showvars">";
echo "<br><br><input type="submit" name="tst" value="calc">";
echo "</form>";
if ($action == 'showvars')
{
echo $var1;
echo $var2;
}
?>
I tested the above code and it works for me.
Posted: Tue Jun 24, 2003 8:08 pm
by McGruff
It could be you have register globals off (which is good).
Code: Select all
<?php
// did you echo these or $_POST['variable']?
echo $_POST['var1'];
echo $_POST['var2'];
// general debugging of $_POST (and other) arrays:
echo '<pre>';
print_r($_POST);
echo '</pre>';
?>
Posted: Wed Jun 25, 2003 2:00 am
by JeffElkins
m@ndio wrote:it could be a bug in your i.e. or something as you have not set your action value in your form.
That was the problem.
Thanks for the replies!
Posted: Wed Jun 25, 2003 2:32 am
by m@ndio
thought so I had it once
