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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:40:09+00:00 2026-05-16T16:40:09+00:00

I’m having a little problem getting my data to submit. I’m trying to make

  • 0

I’m having a little problem getting my data to submit. I’m trying to make a simple chat box using PHP and Ajax, but whenever I try to submit data it will only post after it has been submitted several times. I’m hoping somebody could tell me the problem with me code.

I’m a very novice coder and this is my first time using this site so be nice if its an obvious mistake ^^”

The main chatbox:

<head>
<link href="CSS.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function sendmessage()
{
if (window.XMLHttpRequest)
  {
  xmlhttp=new XMLHttpRequest();
  }
else
  {
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

var name=encodeURIComponent(document.getElementById("name").value); var message=encodeURIComponent(document.getElementById("message").value); xmlhttp.open("POST","insert.php",true); xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); xmlhttp.send("name="+name+"&message="+message); } </script> </head> <body> <center> <table width="600"> <tr> <td height="400"> <center> <iframe src ="output.php" width="580px" height="386px"> <p>Your browser does not support iframes.</p> </iframe> </center> </td> </tr> <tr> <td> <form method="POST"></br> &nbsp Name: &nbsp &nbsp &nbsp <input type="text" id="name" autocomplete="off" size="15"/><br/><br/> &nbsp Message: &nbsp <input type="text" id="message" autocomplete="off" size="70"/> &nbsp <input type="submit" value="Send" onclick="sendmessage()"/> </form> </td> </tr> </table> </center> </body>

The PHP file which reads the input data and writes it to a log file:


<?php
$name='<table><tr><td width="100%">'.$_POST['name']." Says:</td>";
$message="<table><tr><td>".$_POST['message']."</td></tr></table></br>\n"; 
$time="<td>".date("d/m/y-G:i")."</td></tr></table>";
$log = "log.file";
$write = fopen($log, 'a') or die("Can't open file");
fwrite($write, $name);
fwrite($write, $time);
fwrite($write, $message);
fclose($fh);
?>

  • 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-16T16:40:10+00:00Added an answer on May 16, 2026 at 4:40 pm

    I just grabbed your code and tested it out in my computer. Did some small changes but everything if working fine. I just commented

    xmlhttp.execCommand('mceRemoveControl',false,'content');

    then everything worked fine on FireFox.

    Below you can see the code that I ran:

    HTML:

    <html>
    <head>
    <!--link href="CSS.css" rel="stylesheet" type="text/css"-->
    <script type="text/javascript">
    function sendmessage()
    {
    if (window.XMLHttpRequest)
      {
      xmlhttp=new XMLHttpRequest();
      }
    else
      {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    
    
    var name=encodeURIComponent(document.getElementById("name").value);
    var message=encodeURIComponent(document.getElementById("message").value);
    xmlhttp.open("POST","insert.php",true);
    xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    //xmlhttp.execCommand('mceRemoveControl',false,'content');
    xmlhttp.send("name="+name+"&message="+message);
    }
    </script>
    </head>
    <body>
      <center>
        <table width="600">
          <tr>
            <td height="400">
              <center>
                <iframe src ="output.php" width="580px" height="386px">
                  <p>Your browser does not support iframes.</p>
          </iframe>
              </center>
            </td>
          </tr>
          <tr>
            <td>
              <form method="POST"></br>
              &nbsp Name: &nbsp &nbsp &nbsp 
        <input type="text" id="name" autocomplete="off" size="15"/><br/><br/>
        &nbsp Message: &nbsp
        <input type="text" id="message" autocomplete="off"  size="70"/> &nbsp
        <input type="submit" value="Send" onclick="sendmessage()"/>
              </form>
            </td>
          </tr>
        </table>
      </center>
    </body>
    </html>
    

    PHP:

    <?php
    try{
        $name='<table><tr><td width="100%">'.$_POST['name']." Says:</td>";
    $message="<table><tr><td>".$_POST['message']."</td></tr></table></br>\n"; 
    $time="<td>".date("d/m/y-G:i")."</td></tr></table>";
    $file = "output.php";
    $write = fopen($file, 'a') or die("Can't open file");
    fwrite($write, $name);
    fwrite($write, $time);
    fwrite($write, $message);
    fclose($write);
    }catch(Exception $err){
        echo $err; 
    }
    ?>
    

    I just tried in FireFox 3.6 Safari 5 and Chrome 6. I’m using a Mac so I didn’t tried in IE. In those 3 browsers everything worked fine after the line that I told you at the beginning. Could you proved more details about your problem?

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm trying to create an if statement in PHP that prevents a single post
I'm making a simple page using Google Maps API 3. My first. One marker
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

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.