I made a form with variable rows, see this script:
<?php
$result = mysqli_query($con,"SELECT * FROM features, articles WHERE features.assortment='$categorypages' AND articles.id='$articleid' ORDER BY features.id ASC);
while($row = mysqli_fetch_array($result))
{
$featuresid = $row["id"];
$name = $row["name"];
$nameshort = $row["nameshort"];
$inzichtelijk = $row["inzichtelijk"];
$assortment = $row["assortment"];
$columnimput = $row[$nameshort];
?>
<tr>
<td align="left" valign="top"><?php echo $name ?>:</td>
<td align="left" valign="top">
<input name="articleid[]" type="hidden" value="<?php echo $articleid ?>">
<input name="column[]" type="hidden" value="<?php echo $nameshort;?>">
<textarea name="imput[]" cols="30" rows="3"><?php echo $columnimput;?></textarea></td>
</tr>
<?php }?>
<tr>
<td align="left" valign="top"> </td>
<td align="left" valign="top"><input type="submit" name="submitarticle" value="Save"></td>
</tr>
</form>
</table>
This works fine. With the following foreach-loop I want to update my database, but only numbers are updated. Script:
<?php if(isset($_POST['submitarticle'])) {
$articleid = $_POST['articleid'];
$column = $_POST['column'];
$imput = $_POST['imput'];
foreach($column as $key => $id) {
echo "column: ".$id.", imput: ".$imput[$key].", artikel: ".$articleid[$key].",<br> ";
$sql="UPDATE articles SET ".$id."=".$imput[$key]." WHERE id=".$articleid[$key]."";
$result=mysqli_query($con,$sql);
}
echo "<br>De wijzigingen zijn succesvol opgeslagen.<br>";
}
When there is text in $input nothing will be updated. The echo in the foreach-loop shows both numbers and text.