0

I have a form on a single page, if it don't have a id I want it to insert. but if there is an id then update.

I am having difficulties getting the form values to display in the button.

I am also not sure my if or else if statement is plausible.

<?php
function myform(){
    if(isset($_POST['add'])) {
        if ($myform_id > 0) {
            //my insert query here      
            $btn_value = "add";
            $btn_name = "add";

        }elseif(isset($_POST['edit'])){
            //my update query here        
            $btn_value = "edit";
            $btn_name = "edit";
        } 
    }
}
?>

My form button

<input type="submit" name="<? $btn_name?>" value="<? $btn_value?>">
3
  • plz share more code. Commented Sep 30, 2016 at 16:33
  • 1
    <input type="submit" name="<? $btn_name?>" value="<? $btn_value?>"> you are not echoing $btn_name Commented Sep 30, 2016 at 16:33
  • 1
    dont know, r u expecting, you will get $btn_name = "add"; without form submission? Commented Sep 30, 2016 at 16:35

2 Answers 2

0

try this

<input type="submit" name="<?echo $btn_name;?>" value="<? echo $btn_value;?>">
Sign up to request clarification or add additional context in comments.

1 Comment

@namiramir still says undefined variable on input
0

within the php tag itself give the following statement

print "<input type='submit' name='$btn_name' value='$btn_value'>";

Comments

Your Answer

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