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 6587865
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:58:25+00:00 2026-05-25T16:58:25+00:00

On my webpage I have a textarea where the user inputs all kind of

  • 0

On my webpage I have a textarea where the user inputs all kind of characters.
When he saves it I want to send the data using AJAX to the server for storing in the database. After this, the server will send back the data to the browser to be displayed.

Which is the right way to do this?
Right now I make an AJAX call:

function update()
{
    $.ajax({
        type: "POST",
        url: "ajax/update.php",
        data: "ID=" + ID + "&value=" + encodeURIComponent($('#newText').val()),
        success: function(html) {
            $('#l' + CurrentID).html(decodeURIComponent(html));
        }
    });
}

and my php file looks like this:

<?php

$ID = $_POST["ID"];
$value = nl2br(urldecode($_POST["value"]));
if (get_magic_quotes_gpc()) {
    $value = stripslashes($value);
}
$value = htmlentities($value);

$value = str_replace("<br />", "", $value);
$value = str_replace("<br/>", "", $value);
$value = str_replace("<br>", "", $value);

mysql_query("update MyTable set value = '$value' where id = $ID");

echo html_entity_decode(urlencode($value));
?>

I am not sure I am doing the things right. For sure I can see now the problem with spaces being replaced by + sign. But I am thinking that there is something I am not doing it by the book.

  • 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-25T16:58:26+00:00Added an answer on May 25, 2026 at 4:58 pm

    You could improve your AJAX call like this:

    $.ajax({
        type: "POST",
        url: "ajax/update.php",
        data: { ID: ID, value: $('#newText').val() },
        success: function(html) {
            $('#l' + CurrentID).html(html);
        }
    });
    

    Notice how the data is sent using an object. You no longer need to worry about properly url encoding. jQuery takes care of it.

    Also your PHP seems to be vulnerable to SQL injection. You should use prepared statements to avoid this.

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

Sidebar

Related Questions

I have a webpage that the user inputs data into a textarea and then
I have a webpage that retrieves data (via ajax/php) and shows it in an
I have a textarea field on my webpage. I am accepting the user input,
I have dynamic web page with JS. There is a <textarea> and a Send
I have a webpage that when landed on, will detect a user's physical location
I have a <textarea> for user input, and, as they are invited to do,
I'm developing an blog using ASP.NET , and I want that the user can
I have a webpage where there is a textarea within a iframe. I need
I am using JEditable jquery plugin to update some data on my webpage. After
I have this form: <form name=commentform id=commentform action=comment.php method=post enctype=multipart/form-data> Your Name: <textarea maxlength=60

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.