Kandey Posted October 30, 2014 Share Posted October 30, 2014 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 More sharing options...
davidannis Posted October 31, 2014 Share Posted October 31, 2014 Sorry but your description of the issue is really hard to follow without code. Please post it when you can. Link to comment https://forums.phpfreaks.com/topic/292175-problem-with-select-boxes/#findComment-1495330 Share on other sites More sharing options...
QuickOldCar Posted November 4, 2014 Share Posted November 4, 2014 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/292175-problem-with-select-boxes/#findComment-1495667 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.