Jump to content

Recommended Posts

Hey guys,

 

My problem is, iam loading with mysql_fetch_array a table from my database and draw it into my website page.

 

The table is a user table which has an id, user, password and rights(Admin, Mod , User).

 

Only the rights are given out as <select> </select> boxes with the 3 options(Admin, Mod , User).

 

And i also have 1 more column which has for each row a href to a new site with the id of the array_index as paramter.

 

My Problem is i want to know which select box was changed and which option is selected so i can change the rights in my database of this user with the right id.

 

 

At the moment i cant post the code in here cause i have a problem with my laptop now.

 

 

I hope you can help me,

 

Thank you

Edited by Kandey
Link to comment
https://forums.phpfreaks.com/topic/292175-problem-with-select-boxes/
Share on other sites

A demo script of how you can do it

<?php
//dummy data to simulate row information from database
$row = array(
    "rights" => "mod"
);


echo "<form action='' id='my_form' method='POST'>";
echo "<select name='rights'>";

//rights array
$rights = array(
    "admin",
    "mod",
    "user"
);

//check if post set and use that, if not use row value
if (isset($_POST['rights']) && trim($_POST['rights']) != '') {
    $selected_rights = trim($_POST['rights']);
} else {
    $selected_rights = $row['rights'];
}

//loop the rights array with the proper selection selected
foreach ($rights as $permission) {
    if ($selected_rights == $permission) {
        echo "<option value='" . $permission . "' selected='selected'>" . $permission . "</option>";
    } else {
        echo "<option value='" . $permission . "'>" . $permission . "</option>";
    }
   
}

echo "</select>";
echo "<input type='submit' name='submit' value='Submit'>";
echo "</form>";
?>
Edited by QuickOldCar
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.