输出数据的循环仅允许对第一记录进行改变

时间:2015-08-19 13:05:11

标签: php jquery ajax forms loops

我有一个页面,我可以接受/拒绝用户。一旦用户被接受,我就会更改成员资格组以授予权限级别,并基本上允许他们登录。但是出于某种原因,如果我尝试更改任何不是第一个人的数据输出用户的组级别,它会改变第一个人的数据。

所以如果我有这样的清单......

-Mike

-Bob

-Suzy

如果我试图改变鲍勃的小组,那就会改变迈克的小组。

为什么会这样?

以下是帮助我看到无法看到的内容的代码。

$con2 = mysqli_connect("localhost", "", "", "");
$run2 = mysqli_query($con2,"SELECT * FROM user_requests ORDER BY id DESC");
$runUsers2 = mysqli_query($con2,"SELECT * FROM users ORDER BY id DESC");
$numrows2 = mysqli_num_rows($run2);

    if( $numrows2 ) {
        while($row2 = mysqli_fetch_assoc($run2)){
            if($row2['status'] == "Approved"){
            //var_dump ($row2);

                $approved_id        = $row2['user_id'];
                $approved_firstname = $row2['firstname'];
                $approved_lastname  = $row2['lastname'];
                $approved_username  = $row2['username'];
                $approved_email  = $row2['email'];

    if ($approved_firstname == true) {
        echo "Name - ". $approved_firstname . " " . $approved_lastname . "</br>" . 
            "Username - ". $approved_username . "</br></br>"
?>
<div class="change_group_button"> 
     <a class="change_group" href="javascript:void(0)">Change User Permission</a>
</div><br>
<div id="light" class="change_group_popup">
    <a class="close" href="javascript:void(0)">Close</a>
 <div class="group_success" style="color: red;"></div><br>
    <form id="update_group" action="" method="POST" accept-charset="utf-8">
       <div class="field">
        <label for="group">Group</label>
        <input type="hidden" value="<?php echo $approved_id; ?>" id="approved_id" name="id" />
        <input type="hidden" value="<?php echo $approved_firstname; ?>" id="approved_firstname" name="firstname" />
        <input type="hidden" value="<?php echo $approved_lastname; ?>" id="approved_lastname" name="lastname" />
        <input type="hidden" value="<?php echo $approved_username; ?>" id="approved_username" name="username" />
        <input type="hidden" value="<?php echo $approved_email; ?>" id="approved_email" name="email" />
        <select id='group_id' name='group' required>
            <option value=''><?php echo htmlentities($group); ?></option>
            <option value="1">Bench</option>
            <option value="2">Spectator</option>
            <option value="3">Team Member</option>
            <option value="4">Commissioner</option>
            <option value="6">Deny</option>
        </select>
    </div>
    <input type="submit" value="submit" name="group">
    </form>

AJAX调用

$(document).ready(function () {

    $('#update_group').on('submit', function (event) {
    event.preventDefault();
        $.ajax({
            url: 'user_group_update.php',
            type: 'POST',
            data: {
            id: $("#approved_id").val(), //id
            firstname: $("#approved_firstname").val(), //firstname
            lastname: $("#approved_lastname").val(), //lastname
            username: $("#approved_username").val(), //username
            email: $("#approved_email").val(), //email
           // update_group: $("#group_id").val() //group level
          update_group: $(this).find( "#group_id option:selected" ).val()
        },
            success: function (data) {
                //do something with the data that got returned
                $(".group_success").fadeIn();
                $(".group_success").show();
                $('.group_success').html('User Permission Level Changed!');
                $('.group_success').delay(5000).fadeOut(400);
                //alert(data);
            },
             error: function(jqXHR, textStatus,errorThrown )
            {
              // alert on an http error 
              alert( textStatus +  errorThrown );
            }
        });
        return false;
    });
});

0 个答案:

没有答案