jasper182 Posted January 12, 2007 Share Posted January 12, 2007 I am currently working on a simple AJAX page that reads the value of a textarea and then writes that to my MySQL database everytime the contents of the textarea changes. For some reason though, every character is stored in the database fine except for the +. Whenever I type that, then check the view page any + that I have typed are gone. I checked the database and they are not stored there either. I pass the contents of the textarea to my update.php page which reads the new value and updates the record in the database. Basically, the code on the update.php page is :$newContent = addslashes($_POST['content']);$query="UPDATE files SET Content='$newContent' WHERE FileID='1'";$result=mysql_query($query);The FileID=1 is just so I could test it by overwriting the same record. The top line is the only time that I reference the data sent to update.php, so I don't know where it could be disappearing. Is there something I'm missing? Any direction would be greatly appreciated, and thanks in advance for sharing your knowledge with me. Quote Link to comment https://forums.phpfreaks.com/topic/33833-mysterious-vanishing/ Share on other sites More sharing options...
Jessica Posted January 12, 2007 Share Posted January 12, 2007 Try this:$newContent = addslashes($_POST['content']);print $newContent;Are the +'s there? If not, it's your javascript. Are you using a js framework to do your ajax call? Quote Link to comment https://forums.phpfreaks.com/topic/33833-mysterious-vanishing/#findComment-158754 Share on other sites More sharing options...
jasper182 Posted January 12, 2007 Author Share Posted January 12, 2007 I'm simply javascript to call the update.php page. Here is my function:var OLDhttpvar4;var httpvar4;function getEditor() {if(window.XMLHttpRequest){ httpvar4 = new XMLHttpRequest();}else{ httpvar4 = new ActiveXObject("Microsoft.XMLHTTP");}var params;params = "username=Jasper" if (document.getElementById('mainEditor') != null) { params = params + '&content=' + (document.getElementById('mainEditor').value);}httpvar4.open('POST', 'editorBox.php', true);httpvar4.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); httpvar4.setRequestHeader("Content-length", params.length);httpvar4.setRequestHeader("Connection", "close"); httpvar4.send(params); httpvar4.onreadystatechange = function() {if (httpvar4.readyState == 4) { if(OLDhttpvar4 != httpvar4.responseText && httpvar4.responseText != 'No Print') { document.getElementById("contentBox").innerHTML = (httpvar4.responseText); OLDhttpvar4 = httpvar4.responseText; }}};Also, I looked at the values being sent and the +'s are all getting to update.php. Thanks for helping me out. Quote Link to comment https://forums.phpfreaks.com/topic/33833-mysterious-vanishing/#findComment-158762 Share on other sites More sharing options...
btherl Posted January 12, 2007 Share Posted January 12, 2007 "+" happens to be the url encoded value for space. Could there be some url decoding going on (perhaps automatically)?To debug it, I would check first that the + are being sent to update.php, then that the + are being received by update.php (using what jesirose suggested). Once you've found where they are disappearing you can focus in on that. Quote Link to comment https://forums.phpfreaks.com/topic/33833-mysterious-vanishing/#findComment-158842 Share on other sites More sharing options...
jasper182 Posted January 12, 2007 Author Share Posted January 12, 2007 Ok, it looks like it is being sent, but like you said its not making it from my javascript to update.php. Is there a way to send the Post variable as a string? I tried putting it in quotes and that didn't work, it just added quotes around what I submitted. Thanks for your assistance. Quote Link to comment https://forums.phpfreaks.com/topic/33833-mysterious-vanishing/#findComment-158845 Share on other sites More sharing options...
btherl Posted January 12, 2007 Share Posted January 12, 2007 Hmm.. what if you urlencode the "+" before sending it? + encodes to %2B. If you can send %2B from javascript and receive + in php, then all you'll need to do to fix it is to encode it before sending.A good test would be to use your existing code but hardcode "content=%2B". Quote Link to comment https://forums.phpfreaks.com/topic/33833-mysterious-vanishing/#findComment-158850 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.