Hi everyone, I have a strange thing happening when I update my form.
On the form there are a number of input fields, item cost,item name, item description.

If I update the item cost, this updates without any problems, but it also updates the item description, duplicating the description.
The description is in a text area input box.
How do i stop this duplication, or is there a way to check if any of the content has changed to only update the changed content ?

Seem strange as it is only happening on the text area input box ;)

Dani AI

Generated

A few quick notes and a small checklist that often finds this exact symptom (one field updates cleanly while a textarea value gets duplicated). was right that seeing the code helps; since later fixed it, here are likely causes and practical checks so others can diagnose the same issue.

Common culprits to inspect:

  • Server-side concatenation: look for .=, string concatenation or SQL that uses CONCAT()/description = description || ... instead of replacing the column.
  • Duplicate form elements: search the HTML for more than one name="description" (hidden field, template duplication, etc.).
  • Double-processing: the update handler might run twice (included twice, or JavaScript submits twice). Check server logs and the browser Network tab for duplicate POSTs.
  • Bad update SQL or trigger: ensure the UPDATE statement sets columns to the new value rather than appending, and check for DB triggers that modify the field.
  • Array vs scalar: if the textarea name was accidentally description[], PHP may receive an array and your code may implode/concat it.

Simple debug steps: log var_export($_POST, true) before the update, fetch the current DB row and log its values, then log the exact SQL and bound parameters you execute. That will reveal whether the code is appending the old value or getting duplicate submissions.

If the goal is to update only changed fields, a common pattern is: SELECT the current row, compare each $_POST value (use trim() for text), build an UPDATE only for changed columns, and execute with prepared statements. Example (PDO):

$stmt = $pdo->prepare('SELECT description, cost FROM items WHERE id = :id');
$stmt->execute([':id' => $id]);
$row = $stmt->fetch(PDO::FETCH_ASSOC);

$updates = []; $params = [':id' => $id];

if (trim($_POST['description']) !== trim($row['description'])) {
  $updates[] = 'description = :description';
  $params[':description'] = $_POST['description'];
}
if ($_POST['cost'] !== $row['cost']) {
  $updates[] = 'cost = :cost';
  $params[':cost'] = $_POST['cost'];
}

if ($updates) {
  $sql = 'UPDATE items SET ' . implode(', ', $updates) . ' WHERE id = :id';
  $pdo->prepare($sql)->execute($params);
}

Final tips: use Post-Redirect-Get to avoid resubmits, normalize whitespace when comparing, and add a short log step to capture the exact values being written—those logs usually point straight to the bug.

Recommended Answers

All 2 Replies

Hard to guess what's wrong without some code.

Thanks for your reply, But I have this sorted now,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.