Hi there! I am currently having troubles sending the name of a submit button to another page. The code for the button is as follows; <form method='post' action='edit.php'><input type='submit' name='ValueIamTryingToGet' style='width:48px' value='Edit'/></form> And the request from the edit.php field is $value=$_REQUEST['name']; echo"Value: $value<br/><br/>"; But, the value is always blank on the paged 'edit.php'. Could anyone please advise on how I may be going wrong? Thanks in advance!
The name field is used to identify the field. The value is stores in the value attribute. The right code would be: <form method='post' action='edit.php'><input type='submit' name='somename' style='width:48px' value='Edit'/></form> HTML: $value=$_REQUEST['somename']; echo"Value: $value<br/><br/>"; PHP: This should output the value 'Edit' from your input field identified by the name 'somename'
$value=$_REQUEST['[COLOR="Red"]ValueIamTryingToGet[/COLOR]']; echo"Value: $value<br/><br/>"; Code (markup):
Thanks for the replies. But this is sort of the reverse of what I want to achieve. I was planning to have an ID number that could be of any value attached to a submit button. So, the 'name' variable would be $id - which is derived from a MySQL database. $id could be anything depending on the query and there would be a table of submit buttons. So, I cant really do... $value=$_REQUEST['ValueIamTryingToGet']; echo"Value: $value<br/><br/>"; as ValueIamAmTryingToGet could be anything. Hopefully what I am trying to do makes sense. Thanks again
I dont see how 'array search' would work in this case as I dont have an array to search from. I am trying to get a virtually random numer that is assigned to a submit button.
What if I want the contents and the contents contain a random value. How would I go about getting the value of the button. I'll give you some more background as to what I am trying to do. I have a MySQL database that is full of 'listings'. Each listing has an auto-increment ID column. I want to be able to view all current listings and have an edit or delete button next to each listing and then send the value of the ID through a submit button over to another page and act accordingly to the button that was pressed. Something like DELETE FROM Listings WHERE id=$submit_button_value Thanks again!
$_POST is the array you search, if you print_r($_POST) you get: Array ( [ValueIamTryingToGet] => Edit ) Code (markup): so by using $value = array_search('Edit',$_POST); PHP: you get the name of the field
@Narrator Actually, I have tried what you explained and it has worked exactly as I wanted. Thanks heaps for everyones help!
Well thank me that is In the future I would try the suggestions from people before saying it doesn't work. Because you never know you could learn something new one day.
I dont believe I ever said that something 'didn't work'. I will say that I didn't fully understand the answer though, until I read deeper and put it into practice. Thanks again though.