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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:31:29+00:00 2026-06-07T09:31:29+00:00

Me and a friend are trying to make a commenting system for our website,

  • 0

Me and a friend are trying to make a commenting system for our website, We have a somewhat simple bit of code to insert values into a mysql database to then later be read and displayed as comments, however the data is not sending correctly to the table at the moment. We are both fairly new to ajax, php and mysql so it may be just a stupid mistake! 😛

The html:

<form id="postComment" action="Comments.js"  method="post"> 
<input type="email" name="email" onchange="checkEmail();" id="email" /> </br>
<div id ="emailerror">
<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" onclick="commentUpload();" />



</form>

The Javascript file:

function commentUpload() //uploads comment to sQl table
{
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 articleName = document.getElementById("articleName") gets the article name

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,true);
xmlhttp.send();

}

And the php:

<?php 

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


$query="INSERT INTO Comments
VALUES (1, email, username, content)";


mysql_query($query);
mysql_close();
?> 

Thanks for any help in advance!

  • 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-07T09:31:31+00:00Added an answer on June 7, 2026 at 9:31 am

    So this may be me, but I would suggest you don’t use any javascript when adding or uploading the comments; ajax can provide some wonderfully powerful code, but it’s probably be better to use it when querying from the database on the clientside as opposed to inserting to the database on the serverside!

    You HTML code should instead jump directly to the PHP, as opposed to being transitioned through the AJAX as you had previously programmed. And instead of using some javascript to change between $_POST and $_GET, you can simply change the method in the HTML.

    <form id="postComment" action="comments.php" method="get">
    

    Next, you must be sure to include a connection to your database. w3Schools has a nice tutorial on establishing connections. At the same time, you must also be sure to concatenate your parameters that you got from the $_GET into the query string using periods.

    <?php 
    
        $email =mysql_real_escape_string($_GET['email']);
        $username = mysql_real_escape_string($_GET['username']);
        $content = mysql_real_escape_string($_GET['content']);
    
        $connect = mysql_connect("server","name","password");
        if (!$con) {die('Unable to connect..!!';}
        mysql_select_db("database", $connect);
    
        $query = "insert into Comments values (1,'" . $email 
        ."', '" . $username . "', '". $content . "')";
    
        mysql_query($query);
        mysql_close();
    
    ?>
    

    I hope that helped! Best of luck with the rest of the website!

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

Sidebar

Related Questions

I m trying to make feed system for my website, in which i have
I have a friend who is trying to make the switch to Linux, but
I'm trying to make a web interface for a c++ game a friend have
I'm trying to make a simple search form on my website and I'm using
I have been trying to make something like Facebook @tagged Friend name add in
I'm trying to make my app publish to all my friend's walls. From what
I'm trying to reproduce the effect our friend @Dr. Molle told us on this
I have a friend who I am trying to teach how to program. He
Trying to help a friend out with a friend out with some assembly code,
Me and my friend are trying to make a webpage which has a flash

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.