-1

I am trying to add special characters into database with JavaScript using encodeURIComponent but it works in localhost and in server adding ' an extra / is also added infront of ' .

How to prevent this?


This is what I have so far:

var qn_text = encodeURIComponent($('#question_text').val()); 

question_text is the field ID.

$.ajax({ type: "POST", url: "<?= site_url('admin/inputdata')?>", 
                       data: "qn_text ="+qn_text, 
                       success: function(msg) { } 
      });

admin is my controller and then to model. If I enter special character like +'&, all these characters are entered in local database correctly. But at server side the characters like ' entered but an extra / is appended infront of ' .

Sathyajith Bhat
  • 21,321
  • 22
  • 95
  • 134
Rabeesh
  • 1
  • 2
  • 2
    Please clarify what the problem is. Show some code, some example data. – Pekka May 18 '11 at 06:56
  • var text = encodeURIComponent(');i want to store this value of text into database.I passed this text through ajax to query.when trying to add into server db an extra / is appended to ' thats problem.but in localhost there no problem occured – Rabeesh May 18 '11 at 07:03
  • 2
    That is not enough. Please describe the problem in more detail. Show some example data and what happens to it. (You can edit your question using the "edit" link) – Pekka May 18 '11 at 07:04
  • @Rabeesh no problem, but this needs more information. Show a full example with example data – Pekka May 18 '11 at 07:38
  • var qn_text = encodeURIComponent($('#question_text').val()); question_text is the feild ID.$.ajax({ type: "POST", url: "= site_url('admin/inputdata')?>", data: "qn_text ="+qn_text, success: function(msg) { } });admin is my controller and then to model. i enter special charectar like +'&, all these charecters entered in local database correctly. but in server side the charectar like ' entered but an extra / is appented infront of ' that is my problem i want to store only ' – Rabeesh May 18 '11 at 07:58
  • You may have magic quotes enabled on the server. (See http://www.php.net/manual/en/security.magicquotes.disabling.php) - do edit your information into your question so others can see it straight away – Pekka May 18 '11 at 08:01
  • magic_quotes_gpc enabled in my server, i just desabled it now all are works fine thank you very much my dear. – Rabeesh May 18 '11 at 09:42
  • Ah, great. You're welcome. I'll add this as an answer so you can close the question. – Pekka May 18 '11 at 09:50

1 Answers1

2

You need to disable magic_quotes on your server. See disabling magic quotes in the PHP manual.

Pekka
  • 442,112
  • 142
  • 972
  • 1,088