Passing Along a Variable

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Passing Along a Variable

Post 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
User avatar
ol4pr0
Forum Regular
Posts: 926
Joined: Thu Jan 08, 2004 11:22 am
Location: ecuador

Post by ol4pr0 »

Wouldnt this have something to do with assignment operators?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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:

Code: Select all

<?php
echo $_POST['IDNO'];
?>
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Thanks for the reply but another question

Post 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?
User avatar
DuFF
Forum Contributor
Posts: 495
Joined: Tue Jun 24, 2003 7:49 pm
Location: USA

Post 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'";
?>
ut1205
Forum Commoner
Posts: 32
Joined: Thu Jan 29, 2004 5:12 pm

Thanks!

Post by ut1205 »

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