Search code examples
phphtmlmysqlsql-updatecontenteditable

Getting contenteditable div's current value and update database


I'm new to web development and I'm trying to create editable database interface. I have got checkboxes in every row and an edit button. I need to update table(in database) when button clicked(rows that are checked). However I can't get current values in cells. I tried contentedittable div to display attiributes.

<?php  while ( $rows = mysql_fetch_array($result)): ?>
  <td align="center" bgcolor="#FFFFFF"><input name="need_delete[<?php echo $rows['UniqueID']; ?>]" type="checkbox" id="checkbox[<?php echo $rows['UniqueID']; ?>]" value="<?php echo $rows['UniqueID']; ?>"></td>
  <td bgcolor="#FFFFFF"><div contenteditable><?php echo $rows['Timestamp']; ?></div></td>
  <td bgcolor="#FFFFFF"><div contenteditable><?php echo $rows['Name']; ?></div></td>
  <td bgcolor="#FFFFFF"><div contenteditable><?php echo $rows['Email']; ?></div></td>
<?php endwhile; ?>

I also tried to give unique names to divs, but it didn't work. I want to get current values from there if possible.

<?php
  if( ! empty($_POST['edit']) ){
   $query = 'UPDATE `asd` SET `Timestamp` = '????' WHERE `UniqueID`='.(int)$id;
   mysql_query($query);
  }
?>

Checkboxes work fine when I delete rows from table. Any suggestions ? Thanks.


Solution

  • There are several javascript libraries that help with this problem: