sw45acp Posted January 17, 2010 Share Posted January 17, 2010 I have a form that is has a single text area for each individual school assignment. These textareas are generated by how many there are in the database. The names of the textareas are assignment[$id] with the assignment's unique id inside. It would be impossible to individually name each one because there could be more than twenty assignments. How can I go about retrieving the text in the textarea and its id to insert it into a database? Is it something like this? $assignment = array(); $assignment = $_POST["assignment"]; foreach ($assignment as $task) { $q = mysql_query("UPDATE table SET `assignment` = '$assignment' WHERE `id` = '$assignment[]'"); Quote Link to comment https://forums.phpfreaks.com/topic/188746-processing-textareas-in-form-with-the-same-array-name/ Share on other sites More sharing options...
MadTechie Posted January 17, 2010 Share Posted January 17, 2010 You basically have it, assuming you have the form like this <input name="assignment[<?php echo $id; ?>]"> you could be able to do this $assignment = $_POST["assignment"]; foreach ($assignment as $ID => $task) { $q = mysql_query("UPDATE table SET `assignment` = '$task' WHERE `id` = '$ID'"); Quote Link to comment https://forums.phpfreaks.com/topic/188746-processing-textareas-in-form-with-the-same-array-name/#findComment-996374 Share on other sites More sharing options...
sw45acp Posted January 17, 2010 Author Share Posted January 17, 2010 ahh yes this works fine. is this re-indexing the array or just reassigning keys? $assignment as $ID => $task i only knew doing something like this was possible because of the forms that are generated in phpmyadmin. Quote Link to comment https://forums.phpfreaks.com/topic/188746-processing-textareas-in-form-with-the-same-array-name/#findComment-996376 Share on other sites More sharing options...
MadTechie Posted January 17, 2010 Share Posted January 17, 2010 its just assigns the array key to ID and the value to task, Quote Link to comment https://forums.phpfreaks.com/topic/188746-processing-textareas-in-form-with-the-same-array-name/#findComment-996381 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.