Tutorial

Professional Tutorial by using project • [PHP & MySQL(PDO)]

Coding for professional Tutorial is given below step by step. Firstly, open PHPMyadmin. Secondly, Learner should create a database in the name of db4pdo and select the database name. Learner should copy paste the same coding as per instruction. Nextly, go to SQL of PHPMyadmin and then copy paste the coding for Database and click upon “go”. Your Database along with its (Database) Name and Tables will be Created. Repeat the same at least for ten times. Must not try to keep in memory, but, try to understand.


Learner copy the code from “db4pdo.sql” file. Nextly, select the database which is created and then go to sql and paste the database code. Click upon “go”.

db4pdo.sql

USE db4pdo;
CREATE TABLE admin
(
id int(4) NOT NULL auto_increment,
email varchar(255) NOT NULL,
password varchar(255) NOT NULL,
PRIMARY KEY(id),UNIQUE KEY(email)
);
INSERT INTO admin VALUES('','admin1@gmail.com','mypassword');
CREATE TABLE members
(
id int(4) NOT NULL auto_increment,
email varchar(255) NOT NULL,
phone varchar(255) NOT NULL,
password varchar(255) NOT NULL,
confirmpassword varchar(255) NOT NULL,
state varchar(255) NOT NULL,
locality varchar(255) NOT NULL,
country varchar(255) NOT NULL,
jobtitle varchar(255) NOT NULL,
jobdetail varchar(255) NOT NULL,
cms varchar(255) NOT NULL,
PRIMARY KEY(id),UNIQUE KEY(email)
);
INSERT INTO members VALUES('','k1@gmail.com','9163978719','12345','12345','west bengal','E-51kalachandpara','china','doctor','dthd dhtth','gjggj');
CREATE TABLE jobtitle
(
jobtitle_id varchar(255) NOT NULL,
jobtitle_name varchar(255) NOT NULL);
INSERT INTO jobtitle VALUES('Teacher','Teacher');
INSERT INTO jobtitle VALUES('Doctor','Doctor');
INSERT INTO jobtitle VALUES('Engineer','Engineer');
INSERT INTO jobtitle VALUES('LIC agent','LIC agent');
INSERT INTO jobtitle VALUES('Student','Student');
CREATE TABLE country
(
country_id varchar(255) NOT NULL,
country_name varchar(255) NOT NULL);
INSERT INTO country VALUES('Afganistan','Afganistan');
INSERT INTO country VALUES('Pakistan','Pakistan');
INSERT INTO country VALUES('China','China');
INSERT INTO country VALUES('USA','USA');
INSERT INTO country VALUES('UK','UK');
CREATE TABLE state
(
state_id varchar(255) NOT NULL,
state_name varchar(255) NOT NULL);
INSERT INTO state VALUES('Assam','Assam');
INSERT INTO state VALUES('Delhi','Delhi');
INSERT INTO state VALUES('Bihar','Bihar');
INSERT INTO state VALUES('Jharkhand','Jharkhand');
INSERT INTO state VALUES('West Bengal','West Bengal');

“script.js” file is created for form validation. Learner create a folder in the name of “index_files”. Copy the code from below and paste the code within “script.js” file which is created in index_files folder.

script.js

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "db4pdo";

try {
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$email=$_POST['email'];
$phone=$_POST['phone'];
$password=$_POST['password'];
$confirmpassword=$_POST['confirmpassword'];
$state=$_POST['state'];
$locality=$_POST['locality'];
$country=$_POST['country'];
$jobtitle=$_POST['jobtitle'];
$jobdetail=$_POST['jobdetail'];



$sql = "INSERT INTO members (email, phone, password, confirmpassword, state, locality, country, jobtitle, jobdetail)
VALUES ('$email', '$phone', '$password', '$confirmpassword', '$state', '$locality', '$country', '$jobtitle', '$jobdetail')";
// use exec() because no results are returned
$conn->exec($sql);
echo "<p style='color:red'>New record created successfully</p>";
} catch(PDOException $e)
{
//echo $sql . "<br>" . $e->getMessage();
echo "<p style='color:red'>The email is already exit. data is not submitted</p>";
}

$conn = null;
?>

<br><br><br>
<a href="registration.php">Go Back</a>


This page is used for login user. First create a “login.php” file and paste the code there. This page is used for entering user in his personal account by his registered email and password. This page is checking user’s email and password is correct or wrong.

login.php