overlordofevil Posted December 17, 2008 Share Posted December 17, 2008 Hello, I have an issue with posting data using check boxes. I am generating a form from data in an mysql table. I get a list people/data with check boxes so I can select which ones I want to make changes to. Here is the form. <form action="home.php" method="POST"> <?php //this subtracts goblin points. $chid = $_SESSION['chapter_id']; $query = "SELECT * FROM demographics join id ON (id.id = demographics.id) where id.chid='$chid' ORDER BY demographics.lastname"; $result = mysql_query($query) or die (mysql_error()); echo "<table border='1' cellspacing='15'>"; echo "<tr><td></td><td>Players Name</td><td>Goblin Point Amount</td><td>Reason</td></tr>"; while ($row = mysql_fetch_array($result)) { extract($row); $uid = $row[id]; $pname= getplayersname($uid); echo "<tr><td><input type='checkbox' name='myarray[]' value='$uid' /></td>\n"; echo "<td>$pname</td>\n"; echo "<td><input type='int' name='amt' size='5'></td><td><input type='reason' name='reason' size='20'></td></tr>\n"; } echo "</table>\n"; ?> <input type="hidden" name="action" value="removegobbies"> <input type="submit" value="Subtract Goblin Points" name="esubmit"> </form> As you can see I have the checkboxes setup as an array and I am using an id as the identifier for what I want to do. now the problem I have is I can't figure out how to have the variables amt and reason post. I know I made a mistake here is the script that is receiving the data from the form. foreach($_POST['myarray'] as $uid) { // $checkbox will have the value assigned to it from uid $amt = $_POST ['amt']; $reason = $_POST ['reason']; $by_id = $_SESSION['user_id']; $aOr = 'rem'; $date = date("Y-m-d"); $chid = $_SESSION['chapter_id']; $pname = getplayersname($uid); $gobbies = getgoblinpoints($uid); $newgobbietotal = $gobbies-$amt; echo " ID - $uid, Amount - $amt, Reason - $reason, BY - $by_id, $aOr, Date - $date, Chapter - $chid, Original Gobbies - $gobbies, New Gobbies - $newgobbietotal.<p>"; } I went straight to the foreach loop to open up the array and go through it. It works for the id info but the amt and reason just wont come over. now I think its a simple issue of setting up all the data to transfer over as the array but I can't figure out how to do it. any suggestion on how I can correct the code would be appreciated. I'm not really good with arrays but if that's the best way to correct this, please point me to a tutorial or explain a bit about how it works. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/137284-using-checkboxes-to-post-different-values/ Share on other sites More sharing options...
premiso Posted December 17, 2008 Share Posted December 17, 2008 $amt = $_POST['amt']; $reason = $_POST['reason']; Remove the spaces between $_POST and [. I do not think that is kosher (but not 100% sure) I would brush up on your html for forms: <input type='int' name='amt' size='5'></td><td><input type='reason' name='reason' size='20'> That should be: <input type='text' name='amt' size='5'></td><td><input type='text' name='reason' size='20'> There is no such type as int or reason for forms in HTML. Quote Link to comment https://forums.phpfreaks.com/topic/137284-using-checkboxes-to-post-different-values/#findComment-717286 Share on other sites More sharing options...
overlordofevil Posted December 17, 2008 Author Share Posted December 17, 2008 thanks for the suggestion. the issue is the script works if I pull the check box option out and set it up to update 1 file at a time. I am trying to figure out how to convert this all to work with the check boxes so i can get a list that the users can select multiple files to update. I think it is an array issue just trying to figure out how to do the array... Quote Link to comment https://forums.phpfreaks.com/topic/137284-using-checkboxes-to-post-different-values/#findComment-718058 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.