HTML-PHP-post

Sep 8, 2020 PHP

<h2> Distinguishing two or more submit buttons on the same page <h / 2>
It seems to look back on myself.
<!-html->
<form method = "post">
    <label> Last name: <input type = "text" size = "10" name = "fname"> </ label>
    <input type = "submit" value = "submit">
</ form>

<form method = "post">
    <label> Name: <input type = "text" size = "10" name = "name"> </ label>
    <input type = "submit" value = "submit">
</ form>
<? php
if ($ _SERVER ['REQUEST_METHOD'] ==='POST') {
        if (isset ($ _ POST ['fname']) === TRUE) {
            $ btn = ($ _ POST ['fname']);
        }
        if (isset ($ _ POST ['name']) === TRUE) {
            $ btn = ($ _ POST ['name']);
        }
}
?>

If you want to send the send buttons separately for some reason, even if you press either button, both contents will be sent at the same time. To be able to send each individually

<!-html->
<form method = "post">
    <label> Last name: <input type = "text" size = "10" name = "fname"> </ label>
    <button type = "submit" name = "btn" value = "insert"> submit </ button>
</ form>

<form method = "post">
    <label> Name: <input type = "text" size = "10" name = "name"> </ label>
    <button type = "submit" name = "btn" value = "updata"> Submit </ button>
</ form>
<? php
if (isset ($ _ POST ['btn']) === TRUE) {
            $ btn = ($ _ POST ['btn']);
        }
        if ($ btn ==='insert') {
            if (isset ($ _ POST ['fname']) === TRUE) {
                $ fname = ($ _ POST ['fname']);
            }
        if ($ btn ==='updata') {
            if (isset ($ _ POST ['name']) === TRUE) {
                $ name = ($ _ POST ['name']);
            }
?>