Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6226285
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T08:59:44+00:00 2026-05-24T08:59:44+00:00

I have a problem with textarea content which I want to save it in

  • 0

I have a problem with textarea content which I want to save it in a file.
So, an user could write in that textarea some HTML,PHP,JS and/or other tags and it wants to save in a file.
First, I declared a variable in JS which takes the textarea value and send via ajax to PHP.
The PHP creates a file and insert textarea content in that file.

If I write a simple PHP/HTML/JS code in textarea, the created and saved file doesn’t contain anything. It is empty (if I use PHP code in textarea) or sometimes if I write HTML tags in textarea.
Look inside my script :

http://pastebin.com/z6CbSNKC

So, what’s the problem ? The JS is a problem or PHP code ?

Code from pastebin:

/* HTML code */
Filename with extension : 
<input type="text" placeholder="ex: test.css" id="titlecopypaste" /><br/>
<textarea cols="60" rows="10" placeholder="Insert code here" id="content"></textarea><br/>
<select id="choose">
<option value="public" selected="selected">Public</option>
<option value="private">private</option>
<option value="both">Public si private</option>
</select>
<center><button id="submitcopypaste">Done</button><br/>
<p id="status_create"></p>
</center>




/* Javascript code */
$("#submitcopypaste").click(function()
{
    var fisier=$("#titlecopypaste").val();
    var content=$("#content").text();
    var select=$("#choose").val();
    $.ajax({
        type:"POST",
        url:"include/uploadtxt.php",
        data:"fis="+fisier+"&cont="+content+"&sel="+select,
        success:function(ev)
        {
            $(this).hide();
            $("#status_create").html(ev);
        }
});





/* PHP code */
session_start();
include('Files.php'); //the class created by
include('connect.php');
$status="";
if(isset($_POST['fis'],$_POST['cont'],$_POST['sel']))
    {
        $obj=new Files();
        $file=$_POST['fis'];
        $content=$_POST['cont'];
        $selected=$_POST['sel'];

        switch($selected)
            {
            case "public":{
                $status=$obj->createfile("../diskuser/_public/".$file, $content);break;
            }
            case "private":{
                if(isset($_SESSION['utilizator'],$_SESSION['parola']))
                    {
                $cer=mysql_query("select * from user where nickname='".$_SESSION['user']."' and password='".$_SESSION['parola']."'");
                if($cer)
                    {
                        while($info=mysql_fetch_array($cer))
                            {
                                $status=$obj->createfile("../diskuser/".$info['nickname']."/".$file, $content);break;
                            }
                    }
                else
                    {
                        $status="Connection error!";
                    }
                    }
                else
                    {
                        $status="The session has been expired !";
                    }
                    break;
            }
            case "both":{
                $status=$obj->createfile("../diskuser/_public/".$file, $content);
                $cer=mysql_query("select * from user where nickname='".$_SESSION['user']."' and password='".$_SESSION['parola']."'");
                if($cer)
                    {
                        while($info=mysql_fetch_array($cer))
                            {
                                $status=$obj->createfile("../diskuser/".$info['nickname']."/".$file, $content);break;
                            }
                    }
                else
                    {
                        $status="Database connection error !";
                    }
                    break;
            }
            }
    }
else
    {
        $status="Invalid data !";
    }
    echo $status;
    });
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T08:59:44+00:00Added an answer on May 24, 2026 at 8:59 am

    I think you may need encode the textarea content before send it.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have problem in some JavaScript that I am writing where the Switch statement
I have a MultiLine asp:Textbox (a standard html textarea for those non-asp people) that
I have a basic PDF file that I has 5 different blank content areas
I have problem with return statment >.< I want to store all magazine names
I have problem when I try insert some data to Informix TEXT column via
I have a problem with a little .Net web application which uses the Amazon
I have a problem in my project with the .designer which as everyone know
I have a little problem with Codemirror ( http://codemirror.net/manual.html ) My code: $(document).ready(function ust()
So I have an 'export' application that arrives the user at an end page
So I have a normal form with 1 textarea and two hidden inputs, which

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.