Home > Enterprise >  I want to update the recorded in data base. I want to send the "employee_id" on clicking s
I want to update the recorded in data base. I want to send the "employee_id" on clicking s

Time:12-08

I want to update the record of the corresponding id that is sent on clicking save button. I tried button tage, input tage and link tage but there is some mistake that I am making, but I don't know where?

This is my form

            <form method="POST" action="handle_update.php">
                <div >
                    <label for="exampleInputEmail1" >First name</label>
                    <input type="text" name="fname" value="'.$first_name.'"  >
                </div>
                <div >
                    <label for="exampleInputPassword1" >Last name</label>
                    <input type="text" name="last_name" value="'.$last_name.'" >
                </div>
                <div >
                    <label for="exampleInputPassword1" >Email</label>
                    <input type="email" name="email" value="'.$email.'" >
                </div>
                <div >
                    <label for="exampleInputPassword1" >Designation</label>
                    <input type="text" name="designation" value="'.$designation.'" >
                </div>
                <div >
                    <label for="exampleInputPassword1" >Address</label>
                    <input type="address" name="address" value="'.$address.'" >
                </div>
                <div >
                    <label for="exampleInputPassword1" >Date of Joining</label>
                    <input type="date" name="joining_date" value="'.$joining_date.'" >
                </div>
               <a name="update" role = "button" type="submit" href="handle_update.php?ployee_id='.$id2.'">Save</a>  
            </form>

CodePudding user response:

Add a hidden input field that holds the value you want to submit. Change your <a> to a <button> that can submit your form. Change your code to:

<form method="POST" action="handle_update.php">
    <input type="hidden" name="ployee_id" value="' . $id2 . '">
    <div >
        <label for="exampleInputEmail1" >First name</label>
        <input type="text" name="fname" value="'.$first_name.'"  >
    </div>
    <div >
        <label for="exampleInputPassword1" >Last name</label>
        <input type="text" name="last_name" value="'.$last_name.'" >
    </div>
    <div >
        <label for="exampleInputPassword1" >Email</label>
        <input type="email" name="email" value="'.$email.'" >
    </div>
    <div >
        <label for="exampleInputPassword1" >Designation</label>
        <input type="text" name="designation" value="'.$designation.'" >
    </div>
    <div >
        <label for="exampleInputPassword1" >Address</label>
        <input type="address" name="address" value="'.$address.'" >
    </div>
    <div >
        <label for="exampleInputPassword1" >Date of Joining</label>
        <input type="date" name="joining_date" value="'.$joining_date.'" >
    </div>
    <button type="submit" name="update">Save</button>
</form>

More on forms: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/form

More on hidden inputs: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/hidden

  • Related