Simple Form with PHP and Ajax


In this post I will explain how to work with a simple form and the submitted form data is handled by PHP. I think this may helpful for the beginners.

In this example I have used javascript to validate the form and used bit of ajax.

By using ajax I am checking the database if the username or the email is already been used. If so an error message will be shown.

I hope to keep this example very clear and simple as much as possible.

I am using MySql database in my example and to run this example first you need to create a database, named “form” and in that database create a table, named “register” which has three columns as “name”, “username” and “email”.

Here you have the sql for that, just copy and paste the code in your mysql prompt and run it.

CREATE DATABASE `form`;
USE `form`;
CREATE TABLE IF NOT EXISTS `register` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(256) NOT NULL,
  `username` varchar(256) NOT NULL,
  `email` varchar(256) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

SyntaxHighlighter.all();

This entry was posted in Ajax, Javascript, PHP, PHP & Javascript, Uncategorized. Bookmark the permalink.

Leave a comment