Distinguish post request from two buttons

Hi,
If I have two buttons in my form, then how can I distinguish while trying to post the input to php for validation

<form>
   <input type="submit" name="btn_submit" value="Eat Ice Cream" />
   <input type="submit" name="btn_submit" value="Drink lemonade" />
</form>
<?php

if($_REQUEST['btn_submit']=="Eat Ice Cream") {
   print "You eat delicious ice cream to cool down";
} else if($_REQUEST['btn_submit']=="Drink Lemonade") {
   print "You drink refreshing lemonade to cool down";
}

?>

It’s all under the topic of dealing with forms, from which you can read documentation here: https://www.php.net/manual/en/tutorial.forms.php

1 Like