0

Im storing some html code in a mysql database . This code is then displayed on the page .

I have setup an editor where a user can edit the code and save it back to the database . This updates the page.

The problem im having is that when its updated , it deletes parts each time.

mysql:

mysqli_query($connection, "UPDATE website_text SET home = '".$_POST['home']."'");

editor:

<textarea class="form-control" name="home" id="home" value="<?php echo $data['home']; ?>" required></textarea>
Jess
  • 133
  • 3
  • 12

1 Answers1

3

A textarea does not have a value property... You need to put the content of it in it:

<textarea class="form-control" name="home" id="home" required><?php echo $data['home']; ?></textarea>
Blaatpraat
  • 2,829
  • 11
  • 23
  • true, but that's only 50% of the issue – Funk Forty Niner May 11 '15 at 13:02
  • True that, the other part requires more user input. – Blaatpraat May 11 '15 at 13:02
  • Thanks . Whats the other 50% of the issue? – Jess May 11 '15 at 13:03
  • 1
    @Jess [other 50%...](http://stackoverflow.com/questions/30168348/editing-html-stored-in-mysql#comment48442865_30168348). Read up on UPDATE https://dev.mysql.com/doc/refman/5.0/en/update.html – Funk Forty Niner May 11 '15 at 13:03
  • You update the `home` column for every record in the table. Unless you only have 1 record with a column for every page... – Blaatpraat May 11 '15 at 13:04
  • yh , its one record with each column representing a part of a page – Jess May 11 '15 at 13:05
  • 1
    In that case, this is valid (except for the possibility of SQL injection, XSS and such vulnarabilities). I wouldn't recommended working like this (what if you need more pages? A table altering is never recommended!), but your problem is solved... For now. – Blaatpraat May 11 '15 at 13:06