PHP: 2 forms different action pages, only 1 form action works

久未见 提交于 2019-12-12 02:27:25

问题


I have two forms on my page. But the one action page(approve.php) doesn't seem to work. I need to set a field as active for the specific id, if it's approve or rejected. Is there any way to do it on one action page?

Or is there something I am doing wrong below? I blocked out the insert script because I didn't know if it was causing an issue. It was working before when I did the approval first...

Page:

<form method="get" action="approve.php">
            <input type="hidden" name="rows" value="<?php echo $row[0] ?>" />
            <p><a href='approve.php?id=<?php echo $row[0] ?>'><button url="#" class="btn btn-primary">Approve</button></a></p>
            </form>
            <form method="get" action="reject.php">
            <div id="reject-form-<?php echo $row[0] ?>" class="modal hide fade">
                        <div class="modal-header">
                            <a class="close" data-dismiss="modal">&times;</a>
                            <h3><?php _e('Reject Reason'); ?></h3>
                        </div>
                        <div class="modal-body">
                            <div id="message"></div>
                        <div class="controlgroup forgotcenter">
                                <div class="control">
                                    <input id="reject" name="reject" type="text"/>
                                </div>
                        </div>
                </div>
                <div class="modal-footer">
                    <input type="hidden" name="rw_id" value="<?php echo $row[0] ?>" />
                    <a href='reject.php?id=<?php echo $row[0] ?>'><button data-complete-text="<?php _e('Done'); ?>" class="btn btn-primary pull-right" id="forgotsubmit"><?php _e('Submit'); ?></button></a>
                    <p class="pull-left"><?php _e('Please give a short reason for rejecting.'); ?></p>
                    </div>
                </div>
            <p><a data-toggle="modal" href="#reject-form-<?php echo $row[0] ?>" id="rejectlink" tabindex=-1><button url="#" class="btn btn-primary">Reject</button></a></p>
            </form>

Reject:

$id = $_GET['rw_id'];
    $reason = $_GET['reject'];


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

    $update = "UPDATE login_fines_adjudicated SET reject_reason = '$reason' WHERE id ='$id'";
    mysqli_query($dbc, $update) or die('Database error!');

    $update1 = "UPDATE login_fines_adjudicated SET active = 1 WHERE id ='$id'";
    mysqli_query($dbc, $update1) or die('Database error, fine!');

    header('location:adjudication.php');

Approve:

$id = $_GET['rows'];

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

    $updated = "UPDATE login_fines_adjudicated SET active = 1 WHERE id = '$id'";
    mysqli_query($dbc, $updated) or die('Database error, active!');

    /**$insert = "INSERT INTO login_fines(`date`, `time_in`, `time_out`, `value`, `area`, `reason`, `licence`)"
    ." SELECT `date_issued`, `time_arrived`, `time_departed`, `value`, `location`, `violation_reason`, `licence`"
    ." FROM login_fines_adjudicated WHERE id = '$id'";
    mysqli_query($dbc, $insert) or die('Database error, fines!');**/

    header('location:adjudication.php');

Any help would be appreciated!


回答1:


You have to change your code like this :

<form method="get" action="approve.php?id=<?php echo $row[0] ?>">
    <p>
        <input type="submit" class="btn btn-primary" value="Approve" />
    </p>
</form>



回答2:


What error are you getting? I can help if you post the error Have you debug the value you get from the form? what do you get?

You can combine reject and approve in one script, and act different based on the value passed in. and I think post is better than get

<form method="post" action="approve.php">
 <input type="hidden" name="approve" value="<?php echo $row[0] ?>" />
  <p><a href='approve.php?id=<?php echo $row[0] ?>'><button url="#" class="btn btn-     primary">Approve</button></a></p>
</form>

<form method="post" action="reject.php">
 <div id="reject-form-<?php echo $row[0] ?>" class="modal hide fade"> 
 ....
<input type="hidden" name="reject" value="<?php echo $row[0] ?>" />

in action.php,

if(key_array_exists($_POST['approve'])) ...
if(key_array_exists($_POST['reject'])) ...


来源:https://stackoverflow.com/questions/16895268/php-2-forms-different-action-pages-only-1-form-action-works

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!