henk.io
henk.io

Reputation: 306

Remove HTML tags in textaera (Basic CMS)

I am very new to PHP and started making a light weight CMS. I have stored all the body content in the database and the CMS calls it from the database and displays it in a text area to be edited. However I was wondering is there a way to make it display the text without HTML tags. I have tried the strip_tag function however when I hit save on my cms it saves without the html tags! how will I go about making it display the data from the database without HTML tags but when I save it, it will save with the HTML tags! Sorry if this question is not clear but it is quite difficult to explain. Here is my code so far working fine:

<?php include_once "includes/scripts.php"; ?>
<?php include_once "includes/connect.php";?>
<?php include_once "includes/cms_page_security.php";?>
<?php
    $sql = "SELECT * FROM content WHERE id = '5'";   
    $result = mysql_query($sql, $connect);
    $num= mysql_numrows($result);mysql_close();
    $row = mysql_fetch_row($result);
    $pg_content = $row['1'];
if (isset($_POST['saveChanges'])){
    $pgcontent = $_POST['edit'];
    $sql_query = ("UPDATE content SET cage_content= '$pgcontent' WHERE cage_content= '$pg_content'");
    mysql_query($sql_query,$connect);
    header('location: admin_cms_staff.php');
    $feedback = "Updated successfully";
    }
?>
<div id="cms_container"><br>
    <h1>Staff Page<img src="images/three_column_grid_line.png" alt="line"></h1>
      <form id="form1" name="form1" method="post">
         <textarea id="content" name="edit"><?php echo $pg_content; ?></textarea>
         <input type="submit" class="submit_edit" value="Save" name="saveChanges" onClick="alertFunction()">
     </form>
    <p class="logout_btn"><a href="admin_cms.php">Back</a></p>
     <?php if(isset($_POST['saveChanges'])){
        echo $feedback;}?>
    </div><!--cms_container-->
<script>
function alertFunction()
{
var r=confirm("Do you want to save the changes you made to the page?");
if (r==true)
  {
  }
else
  {
    return;
  }
}
</script>
</body>
</html>

Upvotes: 1

Views: 191

Answers (1)

user2824854
user2824854

Reputation:

Change this:

$pgcontent = $_POST['edit'];

to:

$pgcontent = strip_tags($_POST['edit']);

And also change this:

<textarea id="content" name="edit"><?php echo $pg_content; ?></textarea>

to:

<textarea id="content" name="edit"><?php echo strip_tags($pg_content); ?></textarea>

Upvotes: 1

Related Questions