can i use submit button inside a form to access a function in other php file?because i have 2 buttons on same page but want them to do different to query database other to update table..

Recommended Answers

All 2 Replies

Yes, you can use multiple submit buttons in your forms:

submit buttons: When activated, a submit button submits a form. A form may contain more than one submit button.


If a form contains more than one submit button, only the activated submit button is successful.


to access a function in other php file?

Use the action attribute of the form to point a switcher file, there you can redirect or just use include() to perform the pre-selected operation.

Here is an example:


    $print = '';
    $action = '';

        $print = $_POST;

        if(array_key_exists('query', $_POST))
            // do query
            $action = 'query';

        if(array_key_exists('edit', $_POST))
            // edit action
            $action = 'edit';

<!DOCTYPE html>
    <title>Yet Another Form</title>

    <form method="post" action="">
        <input type="text" name="msg" />
        <input type="submit" name="query" value="search" />
        <input type="submit" name="edit" value="edit" />


            echo $action;



Member Avatar for iamthwee

You can either use two forms or you can use jquery to single out your submit functions.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.