John Mark
John Mark

Reputation: 65

How to save inputs wihtout html tags in mysql database?

The problem is after inserting into the database, the html tags like p,h2 etc. is there together with the user's input.

I tried the php function mysqli_real_escape_string but it doesn't work. The html tags are still in the db.

<script src="tinymce/tinymce.min.js"></script>
<?php 
include 'connection.php';

if(isset($_POST['submit'])){
    $msg = mysqli_real_escape_string($conn, $_POST['msg']);
$sql = mysqli_query($conn, "INSERT INTO messages(msg) VALUES('$msg')");
}
?>
    <form action="" method="post">
        <textarea name="msg" id="editor">   </textarea>
        <input type="submit" name="submit" value="Submit">
    </form>

    <script>
        tinymce.init({
  selector: 'textarea#editor',
  auto_focus: 'element1',
  width: "200",
  height: "200"
});
</script>

I want is after saving the inputs there is no html tags in the database.

Upvotes: 0

Views: 492

Answers (2)

CoursesWeb
CoursesWeb

Reputation: 4237

If you want to remove the html tags, you can use strip_tags().

$_POST['msg'] = strip_tags($_POST['msg']);

Upvotes: 1

nice_dev
nice_dev

Reputation: 17805

Use strip_tags() function.

<?php

$msg = strip_tags($msg);

Upvotes: 2

Related Questions