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!
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
[quote="PhpMachine"]Hi
How do I check which button is pressed?
isset() does not work on <button>, but it works for <input type='submit'>
if (isset($_POST['button1'])) { echo "button 1 has been set and it's value is " . $_POST['button1'] ; }
if (isset($_POST['button2'])) { echo "button 2 has been set and it's value is " . $_POST['button2'] ; }
if you want to see if it isn't set then just do the same but put an exclamation mark in front of the isset() function
so
if (!isset($_POST['button1']))
would return true if button 1 is not set
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Both isset() statements returns true for me.
It seems that $_POST["button1"] always returns "Button 1", and is therefore always set (and the equivalent for the second button).
<input type = "submit" name = "myButton" value = "Button 1" />
<input type = "submit" name = "myButton" value = "Button 2" />
<input type = "submit" name = "myButton" value = "Button 3" />
If a user clicks the button with value "Button 3", then your $_POST['myButton'] will have a value of 'Button 3' and nothing else.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.