Simple Chat System Using PHP/MySQL with ajax

Submitted by: 
Visitors have accessed this post 60325 times.

This code will tech you on how to create a simple chat system using php and ajax. The feature of this code is it allow multiple user to send message to each other. Download this code to see how this chat function.

database name: chat

Note: Due to the size or complexity of this submission, the author has submitted it as a .zip file to shorten your download time. After downloading it, you will need a program like Winzip to decompress it.

Virus note: All files are scanned once-a-day by for viruses, but new viruses come out every day, so no prevention program can catch 100% of them.


1. Re-scan downloaded files using your personal virus checker before using it.
2. NEVER, EVER run compiled files (.exe's, .ocx's, .dll's etc.)--only run source code.


I tried this it is working but the problem for me is it's refreshing the page every time .I want to work this chat code without refreshing the page..please help

Can you play sound when new entry added?

Thank's nice bangetz

I can't download it because I'm on a Nintendo 3DS, and so I was wondering if you could put it on my site that would be great -Thanks Emolga

Thank u

Not working
Showing error..Notice: Undefined variable: sender in E:\wamp\www\simplechat\index.php on line 107 Call Stack #TimeMemoryFunctionLocation

Nice chat. I am going to create my own chat. I have a problem with refreshing. Can I use your ajax refresh code in my project?
Best regards.

You are save my time awesome

here u use the post method and call insert in the same page, the save.php is not working. .click() is not being called.

When page refresh repeat the last entered text, how can we avoid this
any way very useful.


hi thanks for your code . may i hav request ?

why is it that everytime i reload the page, it will repeat the message i send.?

I haven't read the code yet but the problem with refreshing the page sounds as if the last message var isn't being cleared after it is posted. therefor when you refresh the page it is in turn resubmitting the last msg

I changed php file to support my DB server and file server. The error always happens:
Could not connect: Access denied for user 'root'@'localhost' (using password: NO)
My user isn´t root anymore. So, do I need make some change in js files?

Solved! Index.php has 2 calls to mysql_connect!
Thank you for the solution!

It is showing the error Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\chat\chat\refresh.php on line 13 please tell me the solution for it.

I get the same error, help..?

Thank u friend ....?

awesome tutorial... being a begineer it was very useful for me

( ! ) Notice: Undefined variable: sender in C:\wamp\www\chat\chat\index.php on line 107 Call Stack #TimeMemoryFunctionLocation 10.0059378088{main}( )..\index.php:0 "/>
argie helo
wewew (=^_^=)
argie helo
argie helo
wewew hi
argie helo

Add new comment

Filtered HTML

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <blockquote> <code> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <th> <img> <h1> <h2> <h3>
  • You may insert videos with [video:URL]
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>, <asp>, <c>, <cpp>, <csharp>, <css>, <html4strict>, <java>, <javascript>, <mysql>, <php>, <python>, <sql>, <vb>, <vbnet>. The supported tag styles are: <foo>, [foo].
  • Lines and paragraphs break automatically.

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.