Jump to content

Recommended Posts

Yes, everything in the form will be passed with the POST data. You could probably implement some JavaScript to run at the time of submission to remove those values, but that's not necessary.

 

What you need to do is implement the solution on the processing page by checking which checkboxes are checked and then only processing the associated values. If you were to show the form and the processing code we could help you further.

Yes, everything in the form will be passed with the POST data. You could probably implement some JavaScript to run at the time of submission to remove those values, but that's not necessary.

 

What you need to do is implement the solution on the processing page by checking which checkboxes are checked and then only processing the associated values. If you were to show the form and the processing code we could help you further.

 

well thanks that helps

 

this is my form kode and i dont have any prosess code yet since  i dont know how to do  it  with this  type of form input

 

 $this->_sql = "SELECT *
                        FROM user";
        $this->_query = mysql_query($this->_sql);


        echo '<div id=users>
        Update ur Admin status<br />
        Username | Admin level | Ban | tids ban format: yyyy-mm-dd h:m:s <br />';

        echo '<form method="Post">';

        while ($user = mysql_fetch_object($this->_query))
        {
            echo ''.$user->username.': ';
            echo '<input type="checkbox" name=check[] value='.$user->id.' />';
            echo '<select name=adminlvl[]>';
            // enum from mysql
            $this->_sql = "SHOW COLUMNS FROM user LIKE 'adminlevel'";

            if ($result = mysql_query($this->_sql))
            {

                $enum = mysql_fetch_object($result);
                preg_match_all("/'([\w ]*)'/",$enum->Type,$values);
                $this->_values = $values[1];
            }
            // end
            foreach ($this->_values as $k => $v)
            {

                if ($v == 1)
                {

                    if ($user->adminlevel == 1)
                    {
                        echo '<option selected value="'.$v.'">User';
                    } else
                    {
                        echo '<option value="'.$v.'">User';
                    }

                }
                if ($v == 2)
                {
                    if ($user->adminlevel == 2)
                    {
                        echo '<option selected value="'.$v.'" >Nyhets Admin';
                    } else
                    {
                        echo '<option value="'.$v.'">Nyhets Admin';
                    }

                }
                if ($v == 3)
                {
                    if ($user->adminlevel == 3)
                    {
                        echo '<option selected value="'.$v.'">Moderator';
                    } else
                    {
                        echo '<option value="'.$v.'">Moderator';
                    }

                }
                if ($v == 4)
                {
                    if ($user->adminlevel == 4)
                    {
                        echo '<option selected value="'.$v.'" selected>Administrator';
                    } else
                    {
                        echo '<option  value="'.$v.'">Administrator';
                    }
                }

            }
            echo '</select>';
            $this->_sql = "SHOW COLUMNS FROM user LIKE 'ban'";
            echo '<select name=ban[]>';
            if ($result = mysql_query($this->_sql))
            {

                $enum = mysql_fetch_object($result);
                preg_match_all("/'([\w ]*)'/",$enum->Type,$values);
                $this->_values = $values[1];
            }
            foreach ($this->_values as $k => $v)
            {
                if ($v == 0)
                {
                    if ($user->ban == 0)
                    {
                        echo '<option selected value="'.$v.'">UnBan';
                    } else
                        echo '<option value="'.$v.'">UnBan';
                }
                if ($v == 1)
                {
                    if ($user->ban == 1)
                    {
                        echo '<option selected value="'.$v.'">Ban';
                    } else
                        echo '<option value="'.$v.'">Ban';
                }

            }
            echo '</select>';
            echo '<input type="text" value="'.date("Y-m-d H:i:s").'" name=bantime[] />';
            echo "<br />";
        }
        echo '<input type="submit" name="submit" value="Save" class="submitbox">';
        echo '</form>';

        echo "<br />";
        echo "</div>";

 

OK, you are naming your input fields so they will be sent/received as array - that is good. But, you are going to need to provide indexes for the fields such that a checkbox and it's related fields can be associated with one another.

 

You are already using the user ID as the value of the checkbox, so you can use that as the index for the field names. Here are the fields I see in your code and one way you could provide indexes

echo '<select name="adminlvl['.$user->id.']">';

//

echo '<select name="ban['.$user->id.']">';

 

Then in your processign code you could do something like this

foreach($_POST['check'] as $userID)
{
    //Get the values to be updated for the selected user ID
    $adminlvl = $_POST['$_POST['check'][$userID];
    $ban = $_POST['$_POST['ban'][$userID];

    //Create query to update selected record
    $query = "UPDATE user SET adminlvl='$adminlvl', ban='$ban' WHERE id = $userID";
}

 

NOTE: that is only a preliminary example. I have left all validation/escaping that should be done.

web3f.jpg

 

Uploaded with ImageShack.us

 

wow this shit is working thanks!!!!

 

thats what i call a mind block..

 

strange it gives  error

 

Warning: Invalid argument supplied for foreach() in C:\Program Files (x86)\VertrigoServ\xxxx\xxx\xxx\xxx\xxxx.php on line 51

 

        foreach ($check as $userID)
        {
            $adminlvlupd = $adminlvl[$userID];
            $banupd = $ban[$userID];
            $bantimeupd = $bantime[$userID];

            $this->_sql = "UPDATE user
                              SET adminlevel='".$adminlvlupd."',ban='".$banupd.
                "',ban_time='".$bantimeupd."'
                              WHERE id='".$userID."'";
            mysql_query($this->_sql) or die(mysql_error());

            echo "user upd";

        }

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.