Jump to content

problem with select boxes


Kandey

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

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>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.