This is kind of confusing, but I'll try my best to explain. I allow a user to view thier posted housing ads at the same time (say they have two ads). At the bottom of each ad, there are two links that say "EDIT AD DELETE AD."
For example, if the user clicks on the "EDIT" link of the first ad, that PHP file (view_ads.php) sends a "file id" of 1 through the link to the edit.php file. Now, we are at the actual file where you make changes to your ad and then click submit. My problem, after I click "submit" button on my form (using PHP SELF to redirect back to a specific block of code still within the edit.php file), I lose the "file id" that I need.
How can I pass a variable within the "action" command of the form to the new block of code within that same file?
Thanks for any help, I can post my code if needed.
Passing variable via form
Moderator: General Moderators
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
What I usually end up doing is
1) Store the file id in a session (requires variable cleanup after)
2) Store the file id in a hidden input field
If you choose #2 your going to have to look out for what method you are accessing the variable.
The easiest way is to simply change $_GET['file_id'] to $_REQUEST['file_id']
1) Store the file id in a session (requires variable cleanup after)
2) Store the file id in a hidden input field
If you choose #2 your going to have to look out for what method you are accessing the variable.
The easiest way is to simply change $_GET['file_id'] to $_REQUEST['file_id']
I tried what you mentioned, and still can't get the value (which is 1) to transfer.
Here is what I am using in the form, with the code in bold the main focus:
I then retrieve the variable by the following, only it is not correctly retrieving it:
I should be echoing a value of 1, but I am echoing nothing.
Thanks for your help, Adam
Here is what I am using in the form, with the code in bold the main focus:
Code: Select all
<p><center>
<form action = "<? echo $HTTP_SERVER_VARS['PHP_SELF']?>" method="post">
<table><tr><td>
<p align="justify"><font size="2" style="Trebuchet MS">Click the button below to delete your ad. This process cannot be reversed, so please make sure that you wish to delete this ad.</font></p></td></tr><tr><td colspan="2" align="center">
<input type="submit" name="delete" value="Delete Ad">
<? echo "<INPUT TYPE= \"hidden\" VALUE=\"$id\"NAME= \"id\">"; ?>
</td></tr></table>
</form>
<BR><BR><br><br><BR><BR><BR><BR><BR><br><br><BR></center></p>Code: Select all
<?
if(isset($_POST['delete'])){
$id=$_REQUEST['id'];
echo $id;
}Thanks for your help, Adam
Are you sure you are echoing?
Code: Select all
if(isset($_POST['delete'])){
$id=$_POST['id'];
echo "the id: $id <br>";
}
if (isset($HTTP_POST_VARS['delete']))
{
$id=$HTTP_POST_VARS['id'];
echo "the other id:$id <br>";
}