tlflow Posted April 13, 2007 Share Posted April 13, 2007 Picture this: I'm returning rows of a list of people in my team. But each row at the end has a dropdown which allows me to chagne that the role for that person. In each option value line I am returning the persons ID and new role seperated by a <space> (for ex. <select name="newteamrole"><option value="5 PointGuard"></select>. Once I submit, I seem to be getting the variables I want by using explode(), and if I do just simple echo commands the strings seem to come out right, but nothing is updating in my database. Here's what I have so far: mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); foreach ($_POST['newteamrole'] as $entry) { $variable = explode(" ", $entry); $newrole = $variable[0]; $person = $variable[1]; // echo ("$person is a(n) $newrole <br>"); $query = "update people SET team_role = '$newrole' where userid = '$person'"; // echo ("update people SET team_role = '$newrole' where userid = '$person' <br>"); } mysql_query($query); mysql_close(); Is there a problem with me doing it this way? Anybody got any idea what I'm doing wrong???? Thanks, TL Quote Link to comment Share on other sites More sharing options...
bubblegum.anarchy Posted April 13, 2007 Share Posted April 13, 2007 You have $variable[0] and $variable[1] the wrong way around... but why are your foreaching the newteamrole post value? anyway try this instead: list($person, $newrole) = explode(" ", $entry); Quote Link to comment Share on other sites More sharing options...
tlflow Posted April 13, 2007 Author Share Posted April 13, 2007 I really appreciate your help on this one! This one has me stumped! I tried the change, yet I'm still getting the same results (nothing is being updated to the database). But to answer your question, I thought I would have to "foreach" variables since I'm returning more than one person at one time. I'm trying to set the role for everyone on a team at the same time in one submit... for example my form would look like this, row1 = Fred --> 5--> <select name="newteamrole"><option value="5 PointGuard"><option value="5 ShootingGuard"><option value="5 Forward"><option value="5 PowerForward"><option value="5 Center"></select> row2 = Jim --> 15 --> <select name="newteamrole"><option value="5 PointGuard"><option value="5 ShootingGuard"><option value="5 Forward"><option value="5 PowerForward"><option value="5 Center"></select> row3 = Jake --> 34 --> <select name="newteamrole"><option value="5 PointGuard"><option value="5 ShootingGuard"><option value="5 Forward"><option value="5 PowerForward"><option value="5 Center"></select> and so on... Role is selected in the newteamrole dropdown and I just have the ID with it (seperated by a space for the explode). Foreach was the only way I could think of to get multiple variables to the next page. Quote Link to comment Share on other sites More sharing options...
tlflow Posted April 13, 2007 Author Share Posted April 13, 2007 MY MISTAKE.....this is so humiliating.... Everything works now. I didnt put the mysql_query($query); line inside of the foreach loop after the $query statement. But hey, everything works now! Thanks again for all your help! TL Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.