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>
5
  • 2
    Are you sure the field in your SQL table is set to text ? Commented May 11, 2015 at 13:01
  • 1
    you need a where clause, otherwise it will update EVERYTHING in your table Commented May 11, 2015 at 13:01
  • yh , the type is text . should the Collation be anything specific? Commented May 11, 2015 at 13:02
  • 1
    the value of a textarea should be between the tags, a textarea doesn't have a value attribute. e.g. <textarea><?php echo $data['home']; ?></textarea> Commented May 11, 2015 at 13:02
  • 1
    Your script is at risk for SQL Injection. Commented May 11, 2015 at 13:02

1 Answer 1

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>
Sign up to request clarification or add additional context in comments.

7 Comments

true, but that's only 50% of the issue
True that, the other part requires more user input.
Thanks . Whats the other 50% of the issue?
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.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.