-1

我一直在尝试提交两个按钮,一个用于删除,一个用于编辑/添加。但我似乎无法正确处理。

HTML:

    <!-- Edit/Delete Account Form -->
        <form method="get" action="edit.php" onsubmit="setTimeout('location.reload()');">
          <div id="edit-form" class="modal hide fade">
                    <div class="modal-header">
                        <a class="close" data-dismiss="modal">&times;</a>
                        <h4><?php _e('Edit/Delete Account'); ?></h4>
                    </div>
                    <div class="modal-body">
                        <div id="message"></div>
                            <div class="control">
                <div id="edit-account-form">
    <table id="add-account" class="table">
        <tbody>
            <tr>
            <td valign="middle">
            Account Number
            </td>
            <td>
            <input type="hidden" id="editid" name="editid" value=""/>
            <input type="text" id="number" name="number" value="Enter Some text here "/>
            </td>
            </tr>
            <tr>
            <td>
            Account Description
            </td>
            <td>
            <input type="text" id="description" name="description" value="Enter Some text here "/>
            </td>
            </tr>
            <tr>
            <td>
            Level 01
            </td>
            <td>
            <input type="text" id="level01" name="level01" value="Enter Some text here "/>
            </td>
            </tr>
            <tr>
            <td>
            Level 02
            </td>
            <td>
            <input type="text" id="level02" name="level02" value="Enter Some text here "/>
            </td>
            </tr>
            <tr>
            <td>
            Level 03
            </td>
            <td>
            <input type="text" id="level03" name="level03" value="Enter Some text here "/>
            </td>
            </tr>
            <tr>
            <td>
            Level 04
            </td>
            <td>
            <input type="text" id="level04" name="level04" value="Enter Some text here "/>
            </td>
            </tr>
            <tr>
            <td>
            Tax
            </td>
            <td>
            <input type="text" name="account" value="Enter Some text here "/>
            </td>
            </tr>
            <tr>
            <td>
            Allow General Journals
            </td>
            <td>
            <select>
            <option selected disabled>Select</option>
            <option>Yes</option>
            <option>No</option>
            </select>
            </td>
            </tr>
            <tr>
            <td>
            Allow Payments
            </td>
            <td>
            <select>Select</select>
            </td>
            </tr>
            <tr>
            <td>
            Allow Expense Claims
            </td>
            <td>
            <select>Select</select>
            </td>
            </tr>
            <tr>
            <td>
            Show On Dashboard
            </td>
            <td>
            <select>Select</select>
            </td>
            </tr>
        </tbody>
</table>
                </div>
                            </div>
                        </div>
                    <div class="modal-footer">
                        <button type="submit" data-complete-text="<?php _e('Done'); ?>" name="add" class="btn btn-primary pull-right"><?php _e('Submit'); ?></button>
                        <p class="pull-left"><button type="submit" name="delete" class="btn btn-primary pull-right"><?php _e('Delete'); ?></button></p>

                    </div>
                </div>
        </form>

PHP:

<?php

    //Account Details
    $number = $_GET['number'];
    $description = $_GET['description'];
    $level01 = $_GET['level01'];
    $level02 = $_GET['level02'];
    $level03 = $_GET['level03'];
    $level04 = $_GET['level04'];
    $id = $_GET['editid'];

    $dbc = mysqli_connect('localhost', 'root', 'root', 'accounting') or die('Connection error!');

    if(isset($_POST['delete'])) { 
     $check = "DELETE FROM accountSlave WHERE `id` = '$id' ";
     mysqli_query($dbc, $check) or die('Database error, delete account!');
     }
    if(isset($_POST['add'])) {      
     //$check = "DELETE FROM accountSlave WHERE `id` = '$id' ";
    $check = "UPDATE accountSlave SET `accountNumber` = '$number', `accountDescription` = '$description', `accountLevel1` = '$level01', `accountLevel2` = '$level02', `accountLevel3` = '$level03', `accountLevel4` = '$level04' WHERE `id` = '$id'";
     mysqli_query($dbc, $check) or die('Database error, add account!');
     }

    header('location:master-accounts.php');

?>

当我有一个查询时它可以工作。我尝试了一个查询来添加和删除,它工作。但是如果单击删除按钮,我需要提交删除,反之亦然。

我按照这篇文章尝试在表单上正确设置多个按钮

任何帮助或建议将不胜感激!

4

2 回答 2

4

您需要使用$_GET而不是$_POST. 它应该像

if(isset($_GET['delete'])) { 

if(isset($_GET['add'])) { 

因为您的表单提交方法GET不是POST

于 2013-07-15T12:59:56.710 回答
0

您必须检查按下了哪个按钮,并根据该按钮进行操作。

你也必须使用$_GETnot$_POST因为你的form methodis GET

if(isset($_GET['add'])) {
    // code for add
} elseif(isset($_GET['delete'])) {
    // code for delete
}
于 2013-07-15T13:00:26.537 回答