Jump to content

processing textareas in form with the same array name


sw45acp

Recommended Posts

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[]'");

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'");

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.