DarkHavn Posted August 23, 2006 Share Posted August 23, 2006 [code]echo '' . $user['name'] . '<input type="checkbox" name=' . $user["name"]. '><br/>';[/code]Ok that's my following check box, it echo's one out for every user that is registered.This form posts to a process.php page, now i'm wondering i've tryed foreach(), while(), but how can i pick this up in the $_POST['']; ?As the name=' . $user["name"]. ' value is whatever comes from the databaseThanks again for the help guys/girls :) Quote Link to comment Share on other sites More sharing options...
jcbarr Posted August 23, 2006 Share Posted August 23, 2006 If I'm not mistaken you have to give it a value or it won't post anything. The name of the input type is the variable that it will POST as, and the value is what that variable is equal to.You need to have both a name and a value for your checkbox.You will need to add the value=' . $user['name'] . ' to your input tag. Also how many of these do you want to be able to select? The way you have it now you will be able to select every single user because the name of the input is different for each one. Quote Link to comment Share on other sites More sharing options...
DarkHavn Posted August 23, 2006 Author Share Posted August 23, 2006 So i would need to loop through the post to get the proper value.Hrmm, well this is just a tester at the moment, but once the script does go live, it will handle alot of accounts.This section is used for deleting users, i've looped through the value's and gotten the name that im after, but i can't seem to split the $_POST array to get the value that i want.I'm abit confused as well on this Quote Link to comment Share on other sites More sharing options...
jcbarr Posted August 23, 2006 Share Posted August 23, 2006 [code]foreach($_POST as $k=>$v){ $sql="DELETE FROM table WHERE userid='$v'"; mysql_query($sql);}[/code]That will simply grab every post variable and attempt to delete any row from the tabel that has a userid set to the value of the post. Quote Link to comment Share on other sites More sharing options...
DarkHavn Posted August 23, 2006 Author Share Posted August 23, 2006 Ok that wasn't working, so i echoed out the variable, and what i got wasArrayonDeletethat was echoing out the $v (value) variable, so i echoed out the $k (key) variable, and got that i was looking for, but it has nearly every post value in it as well (including the ones form the buttons)Hrmm so this has confused me even more lol Quote Link to comment Share on other sites More sharing options...
SammyP Posted August 23, 2006 Share Posted August 23, 2006 That will happen. Prepend something like 'deleteme:' before the username when declaring the Input so that when you loop through the keys you can only bother with ones that start with that.In otherwords you'll get values like this in $_POST[]:deleteme:sam => ondeleteme:bill => onDeleteThe check boxes which are checked should appear in the array and have the value 'on', and those not checked should not appear at all.You might want to build a string of names like this ('sam', 'bill', 'bob') and use the SQL contruct 'In' to remove all of them at once. I hope your names are a unique key in your table, otherwise you should obviously be using one for the deletions. (I hope that's obvious.)Sam. Quote Link to comment Share on other sites More sharing options...
DarkHavn Posted August 23, 2006 Author Share Posted August 23, 2006 Hrmm wouldn't i need to cut the string apart just to get the username it's self without the delete: me segment?Otherwise sql wouldn't recognise the data to delete.Hrmm don't think the name is set up as a unique key, it's in a table with other feilds like last name, email etc, the main being an id that's the primary with an auto_increment extra. Quote Link to comment Share on other sites More sharing options...
DarkHavn Posted August 23, 2006 Author Share Posted August 23, 2006 ? Quote Link to comment Share on other sites More sharing options...
SammyP Posted August 23, 2006 Share Posted August 23, 2006 Yes you would. Hardly a bother though as you can write the statement like this:if (substr($key, 0, 9) == 'deleteme:') $deletelist .= ", ".substr($key, 9);Or something like that.I haven't put quotes around the value in the list as the more serious problem you're going to have is not worrying about a little inelegance in splicing a few string, but rather in accidentally deleting people with the same names. Rather than using names, make sure the table has a numeric primary key and use that. Might be able to get away with is_numeric($key) rather than the string splicing then too. Quote Link to comment Share on other sites More sharing options...
DarkHavn Posted August 24, 2006 Author Share Posted August 24, 2006 Hrmm ok i would do that, but the only problem being that the $key seems to hold some more information, like the submit button name/value, and an arrayThe following code is how ive output it see below [code]if($_POST['agdel']) {array_multisort($_POST);foreach($_POST as $key => $value) {echo "$value<br/>";} }[/code]The following output i get isArrayDeleterandomthe output i want is 'random' how would i access this from the $value variable? as there seems to be the one before that'arraydelete'??? 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.