Page 1 of 1
Passing Along a Variable
Posted: Thu Jan 29, 2004 5:12 pm
by ut1205

I'm new to PHP and to this forum. I hope someone can help. I have a variable that was created on one page by a text box and passed to the next page by a post statement. The Variable is $ID
The page picks it up and works fine. I need to pass this same variable to the next page to perform another task but nothing I've tried works.
I'm wanting to pass $ID to the next page as $IDNO. I' trying to do it with a submit button. Where my confusion comes in is in the "form action" area.
<form action="deleteexe.php?xxx=xxx" method="post">
What goes in the x's.
Then
<INPUT TYPE=SUBMIT NAME="xxx" VALUE="Delete!">
What goes in "xxx"
Finally on page "deleteexe.php what do I have to do to pick up the variable so I can use it as $IDNO for use in a "Delete Query"
Do I need to use a command similar to this:
$IDNO = ("".$HTTP_POST_VARS['xxxxx']."");
Again. I'm new and althought the books are good they don't tell it all.
Thanks in advance
Jim
Posted: Thu Jan 29, 2004 5:29 pm
by ol4pr0
Wouldnt this have something to do with assignment operators?
Posted: Thu Jan 29, 2004 5:33 pm
by DuFF
Ok, once you have submitted to the first page all the variables are in the $_POST[] superglobal. So on the 2nd page (the one the first form submits to) do something like this:
Code: Select all
<form action="deleteexe.php" method="post">
<input type="hidden" name="IDNO" value="<?php echo $_POST['ID']; ?>">
// etc, etc
</form>
What this does is create a hidden field in your form with the value of the $_POST['ID'], which was in the first page. Then when you submit this to the third page you can see the ID by going like this:
Thanks for the reply but another question
Posted: Thu Jan 29, 2004 6:33 pm
by ut1205
I haven't tried it yet but in your example you "echo" it on the third page (deleteexe.php) Is there anying I have to do to get it ready for the Query
$Query = "DELETE from $TableName WHERE ID ='$IDNO'";
or is it automatically there and ready to use even though I can't see any reference to it on page 3.
Thanks for the reply
Jim
Who told me PHP was easy?
Posted: Thu Jan 29, 2004 9:42 pm
by DuFF
You should read more about the POST and GET superglobals. In PHP 4.3 (i think?) they changed register_globals default from on to off. That means that when you submit a variable from a form it submits all the variables in an array called $_POST. Want to see all the variable's being passed by a form? Do this on the page it submits to:
Code: Select all
<?php
echo "<pre>";
print_r($_POST);
echo "</pre>";
?>
You treat $_POST like any other array, so it would be like this:
Code: Select all
<?php
$IDNO = $_POST['IDNO'];
$Query = "DELETE from $TableName WHERE ID ='$IDNO'";
?>
Thanks!
Posted: Fri Jan 30, 2004 11:54 am
by ut1205

Thanks for the replies. Works great. That wasn't in my books.
Be back later with another stupid question.