Note that there are some explanatory texts on larger screens.

plurals
  1. POUpdating MYSQL DB with checkbox and textarea data (in PHP)
    primarykey
    data
    text
    <p>I'm using a table to update a database, the table has 264 checkboxes which can be checked and unchecked then updated on the database. </p> <p>I'm doing this by posting data on the form, using a while loop to set all fields to blank ( the value of the checkbox and the textarea value) for each respective field, then using a foreach loop to update each row in the database with the value of the checkbox. </p> <p>Now, what I want to do is add the textarea value for each ticked checkbox into the database as well, what i cant figure out is how to do this? </p> <p>This is my update code:</p> <pre><code>if (isset($_POST["update"])) { $seolistRes2 = mysql_query($seolistQ) or die(mysql_error()); while ($seolistRow2 = mysql_fetch_array($seolistRes2)) { $wsID1 = $seolistRow2["worksheetID"]; $updateWSQ2 = "UPDATE seo_work SET taskValue=0, taskInfo='' WHERE worksheetID=$wsID1 AND userID=$userID"; mysql_query($updateWSQ2) or die(mysql_error()); } $item = $_POST; foreach($item as $key =&gt; $value) { $wsID = str_replace("checkbox","",$key); if (is_numeric($wsID)) { $updateWSQ = "UPDATE seo_work SET taskValue=$value taskInfo=$value WHERE worksheetID=$wsID AND userID=$userID"; mysql_query($updateWSQ) or die(mysql_error()); header("Location: worksheet.php?y=".$seoworkyear."&amp;userID=$userID&amp;action=success"); } } </code></pre> <p>}</p> <p>This is checkbox and textarea code: (please note this is within a form)</p> <pre><code>$currentTask = ''; echo "&lt;tr class='tr'&gt;"; while ($seolistRow = mysql_fetch_array($seolistRes)) { $taskValue = $seolistRow["taskValue"]; $worksheetID = $seolistRow["worksheetID"]; $taskName = $seolistRow["taskName"]; $taskInfo = $seolistRow["taskInfo"]; if ($taskValue == 1) { $taskDone = "&lt;input type='checkbox' value='1' class='checkbox' name='checkbox".$worksheetID."' id=checkbox'".$worksheetID."' checked='checked' /&gt;". "&lt;textarea class='textarea' name='textarea".$worksheetID."' id=textarea'".$worksheetID."'&gt;" . $taskInfo . "&lt;/textarea&gt;"; } else { $taskDone = "&lt;input type='checkbox' value='1' class='checkbox' name='checkbox".$worksheetID."' id='checkbox".$worksheetID."' /&gt;". "&lt;textarea class='textarea' name='textarea".$worksheetID."' id=textarea'".$worksheetID."'&gt;" . $taskInfo . "&lt;/textarea&gt;"; } if ($currentTask != $taskName) { echo "&lt;/tr&gt;"; echo "&lt;tr class='tr'&gt;"; echo "&lt;td class='task'&gt;".$taskName."&lt;/td&gt;"; } echo "&lt;td class='tick'&gt;".$taskDone."&lt;/td&gt;"; $currentTask = $taskName; } echo "&lt;/tr&gt;"; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload