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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T13:37:38+00:00 2026-05-13T13:37:38+00:00

So on our site we currently have a textarea for commenting on certain items.

  • 0

So on our site we currently have a textarea for commenting on certain items. The site uses AJAX so the user can press the button and see their message fade in (Imagine a Facebook style commenting.)

The jQuery/AJAX:

$(function() {
$("input#comment_submit").click(function() {
var comment = $("#comment_box").val();
var dataString = 'comment=' + comment;
$.ajax({
type: "POST",
url: "app.php?id=<?php echo $id; ?>",
data: dataString,
success: function() {
$("textarea#comment_box").attr("disabled", "disabled")
$("input#comment_submit").attr("disabled", "disabled").val("Comment Submitted!");
$("#comments").prepend("<div class=\"comment new\"></div>");
$(".new").prepend("<a href=\"profile.php?username=<?php echo $_SESSION['username']; ?>\" class=\"commentname\"><?php echo $_SESSION['username']; ?></a><p class=\"commentdate\"><?php echo date("M. d, Y", time()) ?> - <?php echo date("g:i A", time()); ?></p><p class=\"commentpost\">" + comment + "</p>").hide().fadeIn(1000);
}
});
return false;
});
});

The PHP:

if (isset($_POST['comment']))
{
$username = $_SESSION['username'];
mysql_query("INSERT INTO appcomments (app_id, username, comment, date) VALUES ('" . $id . "', '" . $username . "', '" . $comment . "', NOW() )");
}

Also, I’m not sanitizing because it’s a local copy and I’m trying to get this bug out of the way.

Now, I’m having a severe problem with this. Say a user simply submits this comment:

I enjoyed this

It comes up empty when the page fetches it. I checked the database and the comment was left completely empty.

So that’s kind of an odd phenomenon. However, if I addslashes to the $comment when it goes into the database…

if (isset($_POST['comment']))
{
$username = $_SESSION['username'];
$comment = addslashes($_POST['comment']);
mysql_query("INSERT INTO appcomments (app_id, username, comment, date) VALUES ('" . $id . "', '" . $username . "', '" . $comment . "', NOW() )");
}

The previous comment saves to the database.

Now this brings up even more problems. I try to add a line break like so,

I enjoyed this

I hope there are more games like this

Which works, but when I go and try this:

I enjoyed this

I hope there are more games like this

Oh and you rock

That submits a blank into the database.

Lastly, adding an Ampersand into any comment submits a blank.

So at this point I have no clue what to do with my commenting code to fix this. Any help would be accepted and would be much appreciated!

  • 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-13T13:37:38+00:00Added an answer on May 13, 2026 at 1:37 pm

    Try using mysql_real_escape_string before pushing it into the DB

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

Sidebar

Related Questions

Our client's site currently uses forms authentication, so users have to go to the
We currently have a message option on our site that displays any message we
We are currently in the process of refactoring our site and we have decided
I have an XML document that matches our site navigation something like this: <page
I have Selenium running under Cruise Control to test our site once a day.
We currently have a high traffic web site, so are relatively comfortable with web
Our asp.net web site is currently deployed to an IIS7 server. We are setting
Currently I am looking at different CDN networks to bring our site, VOD and
We have a gwt app that uses jcifs to pull the user name from
We are currently using TFS 2010 and have a Team site of SharePoint 2007.

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.