Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    May 2012
    Thanked 0 Times in 0 Posts

    Problem saving content of text area to DB

    I am trying to store my content to the database as soon as user clicks save. This part I have completed, clicking save does in fact save my content to the database, however I have one issue.
    I am using another javascript function to change my textarea content based on the option, and this works fine, until I save after I edited something.
    At the moment the text area gets filled with content from DB based on users choice.
    If I simply save the content without actually editing anything in the textarea (this means even removing one word and adding it back again), everything works fine, but if I change even one letter it still saves it, but the xmlhttprequest does not get a value back and seems to be stuck so that my other method now doesnt work to change to different content.

    This is my html/php code

    PHP Code:
    <select name="headings" id="headings" onchange="Javascript:contentChange(this.value)" >
                            <option readonly="true">Headings:
                            <?php echo $options?>
                        <!-- textarea contains all contents of heading -->
                            <textarea class="contentArea" id="contentArea" name="contentArea" align="left" readonly="readonly" cols="76" rows="12"></textarea><br />
    this is the function that is called on save

    function saveContent()
    	document.getElementById("editing").style.display = 'none';
    	document.getElementById("observing").style.display = '';
    	document.getElementById("contentArea").readOnly = true;
    	var Content = document.getElementById("contentArea");
    	if(window.XMLHttpRequest)// code for IE7+, Firefox, Chrome, Opera, Safari
    		xmlhttp=new XMLHttpRequest();
    	}else// code for IE6, IE5
    		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
    		alert(xmlhttp.readyState+" : "+xmlhttp.status);
    			if(xmlhttp.readyState==4 && xmlhttp.status==200)
    				document.getElementById("contentArea").innerHTML= "saved";	
    and this is the code that my javascript function calls
    PHP Code:
    $content $_GET["content"];

    $self $_SERVER['PHP_SELF'];
    $db_link db_connect('project');

    $textInput mysql_real_escape_string($content);

    // save input into database
    $query "UPDATE project_content SET content='$textInput' WHERE content_id = '$content_id'";
    $result mysql_query($query) or die (mysql_error());



  • #2
    Senior Coder
    Join Date
    Dec 2010
    Thanked 558 Times in 551 Posts
    I don't know if this brings you any closer to a solution, but you are obliged to encode your Ajax parameters to be URI compliant! Otherwise some special characters will be transferred incorrectly or maybe even not at all ...



    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts