Page 1 of 1

Passing variables through multiple pages then DB insert

Posted: Sun Feb 23, 2003 5:55 pm
by JohnnySC
OK as a pHp novice, I ask for your patience. I realize I may be simplistic in my approach, but you have to start somewhere.

Ok, what I'm trying to do is present a form that a user will fill out. Then pass that data into a second form for verification. Then send that second form data to a query for insertion into a mysql DB.


I'll only reference a single input for time's sake.


Page 1
------------------
echo "<form action=\"admin.php?action=addaction\" method=\"post\" name=\"add\" id=\"add\">";
echo "<input type=\"text\" name=\"mnamei\" size=\"50\" maxlength=\"100\">";
echo "<input type=\"submit\" name=\"Submit\" value=\"Submit\">";
echo "<input type=\"reset\" name=\"Reset\" value=\"Reset\">";
echo "</form>";
------------------

Page 2
------------------
$mnameval = $_POST['mnamei'];

echo "<form action=\"admin.php?action=addaction2a\" method=\"post\" name=\"add\" id=\"add\">";
echo "<input type=\"text\" name=\"mname\" size=\"50\" maxlength=\"100\" value=\"$mnameval\">";
echo "<input type=\"submit\" name=\"Submit\" value=\"Submit\">";
echo "<input type=\"reset\" name=\"Reset\" value=\"Reset\">";
echo "</form>";
------------------

Page 3
------------------
$mnamevalf = $_POST['mname'];
echo = $mnamevalf;
-----------------

So my question is why doesn't this work? I need to solve this flow problem before I can address the insert.

Any ideas?

Posted: Sun Feb 23, 2003 6:36 pm
by volka
So my question is why doesn't this work?
hard to tell from the snippets. What does not work?
  • In both forms admin.php is the target. How do you switch between the different functions?
  • What does print_r($_POST); tell?
  • os/php/webserver version?

Posted: Sun Feb 23, 2003 7:42 pm
by JohnnySC
I'm passing the info via the url?action=. That way I can use the same page with includes.

Whats not working is that data does not seem to be passed from snippet 2 to 3. All I'm trying to do at this point is echo the value to the screen. Once I solve this data passing problem I can then send it to the insert instead of the echo.

Posted: Sun Feb 23, 2003 9:10 pm
by volka
omg, I'm really blind =]
echo = $mnamevalf;
syntax error, should be echo $mnamevalf; without the equation sign.
May I suggest a slightly different approach? You can do something like

Code: Select all

<?php
$mnameval = $_POST['mnamei'];
?>
<form action="admin.php?action=addaction2a" method="post" name="add" id="add">
	<input type="text" name="mname" size="50" maxlength="100" value="<?php echo $mnameval; ?>">
	<input type="submit" name="Submit" value="Submit">
	<input type="reset" name="Reset" value="Reset">
</form>
<?php
	//other php-cod here
?>
if not faster it is more readable this way