0

I am using php and html. I have two buttons in my table as shown in the image bellow. When I press the Update button, it displayed the correct name and value properties of the Update button. However, when I press the jan_data button, it doesn't show the properties of that button. Instead it shows the name and value properties of the Description text box. I am new to html and can you please tell me what modifications I should do to get the correct value of the jan_data button when I click it. (not allowed to use JavaScript in my website).

<?php
echo "<form action=\"\" method=\"POST\">
<table border=\"1\"><tbody>
<tr>
<td>January:</td>
<td><input id=\"WorkOrder1\" type=\"text\" name=\"val1\" value=\"$\" /><input type=\"submit\" name=\"january_box\" value=\"jan_data\" /></td>
<td>february:</td>
<td><input id=\"WorkOrder2\" type=\"text\" name=\"val2\" value=\"$\" /></td>
<td>March:</td>
<td><input id=\"WorkOrder3\" type=\"text\" name=\"val3\" value=\"$\" /></td>
</tr>
<tr>
<td>April:</td>
<td><input id=\"WorkOrder4\" type=\"text\" name=\"val4\" value=\"$\" /></td>
<td>May:</td>
<td><input id=\"WorkOrder5\" type=\"text\" name=\"val5\" value=\"$\" /></td>
<td>June:</td>
<td><input id=\"WorkOrder6\" type=\"text\" name=\"val6\" value=\"$\" /></td>
</tr>
<tr>
<td>Description:</td>
<td colspan=\"5\"><input type=\"text\" name=\"description_box\" value=\"description_data\" size=\"44\" /></td>
</tr>
</tbody></table>
<input type=\"submit\" name=\"updatebutton\" value=\"Update\" /></form>";


foreach($_POST as $key => $value){} //Only needs to find which button is pressed    
    echo "<br>key is: $key<br>";
    echo "value is: $value<br>";
?>

enter image description here

2
  • The echo statements are out of the forEach block, please see the {} Commented Jul 21, 2014 at 0:51
  • 1
    For the sanity of others, please consider to use echo only for smaller pieces of HTML; use ?><html><?php for bigger chunks. Commented Jul 21, 2014 at 0:53

1 Answer 1

1

Change:

foreach($_POST as $key => $value){}
    echo "<br>key is: $key<br>";
    echo "value is: $value<br>";

To:

foreach($_POST as $key => $value){
    echo "<br>key is: $key<br>";
    echo "value is: $value<br>";
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for the answer. But this doesn't solve my problem. it will give key and value of all the text boxes and buttons. I only wants to get the value of the button some one clicks.
Look for the value of both the buttons, the one clicked will be set and the other one will be ''
ok, thanks. my bad. I see the difference now. thanks for all of your comments and the help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.