Jump to content

[SOLVED] Updating data from multiple rows


tlflow

Recommended Posts

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

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.