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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:57:06+00:00 2026-06-07T05:57:06+00:00

I am trying to create a comment system for a website using ajax php

  • 0

I am trying to create a comment system for a website using ajax php and mysql. For this I want to send the id of the button clicked to upload a comment (Which will be set to the article name) to an sql database (as well as the comment and some other stuff…)

The system I have at the moment is being rather strange.. If I copy it into jsFiddle it and link to the correct php file on my server it works fine and the id of the button is uploaded to the database.. However if I upload the exact same thing to my website it doesn’t work… Here’s what I have:

Html form:

<form id="addCommentForm"> 
<input type="email" name="email" onchange="checkEmail();" id="email" /> </br>
<div>
<p id="emailerror"> </p>
</div> </br>
<input type="text" name="username" id="username" /> </br>
<input type="text" name="content" id="content" /> </br>
<input type="Button" value="submit" id="Test" onclick="commentSend(this.id);return       false;"/>
</form>

The javascript (external):

function commentSend(clicked_id) 
{

var email = document.getElementById("email").value //gets the user's email
var username = document.getElementById("username").value //gets the user's username
var content = document.getElementById("content").value //gets the comment content
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  };
xmlhttp.open("GET","commentUpload.php?email=" + email + "&username=" + username +    "&content=" + content + "&articleName="+ clicked_id,true);
xmlhttp.send();

return false;

}

And the php:

<?php 
$con = mysql_connect("myserver","myusername","mypassword");
mysql_select_db("mydatabase", $con);

$articleName = mysql_real_escape_string($_GET['articleName']);
$email = mysql_real_escape_string($_GET['email']);
$username = mysql_real_escape_string($_GET['username']);
$content = mysql_real_escape_string($_GET['content']);

if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$query = "INSERT INTO Comments (id, article, email, name, body)    VALUES (NULL, '" . $articleName ."', '" . $email ."', '" . $username . "', '". $content . "')";

mysql_query($query);

mysql_close($con);

?> 

The only thing I can possibly think of is that there is some error with passing the variable this.id to an external javascript file because this is the only value that doesn’t get uploaded to the database…

Anyone any ideas!?

  • 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-06-07T05:57:07+00:00Added an answer on June 7, 2026 at 5:57 am

    You are not encoding your variables for use in a query string.

    What you can do to solve that, is using encodeURIComponent (for all values…) like:

    var content = encodeURIComponent(document.getElementById("content").value);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a nested comment system using PHP and MySQL. But I'm
I am trying to create a dynamic 'page' listing for threads/comments using AJAX. in
So I'm trying to create a comment system in which you can reply to
Im trying to make something like this http://demos.99points.info/facebook_wallpost_system/ which is a comment system. I
I'm trying create a bot which automatically likes Facebook posts. Using Mechanize I can
Ok so I am trying create a login script, here I am using PHP5
Trying to create a background-image slideshow and am getting this error... This is the
I am trying to create a simple RSS parser using the two frameworks. However
I m trying to make feed system for my website, in which i have
I'm trying to make a comment system, identical to the stackoverslow's one. There's a

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.