Question: Open database in phpmyadmin: http://localhost/phpmyadmin Create a new database name login in phpmyadmin. Create a new table: users -- -- Table structure for table `users`

  1. Open database in phpmyadmin: http://localhost/phpmyadmin

  1. Create a new database name login in phpmyadmin.

  1. Create a new table: users

--

-- Table structure for table `users`

--

CREATE TABLE IF NOT EXISTS `users` (

`user_id` int(11) NOT NULL,

`username` varchar(50) NOT NULL,

`password` varchar(50) NOT NULL,

`name` varchar(50) NOT NULL

) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;

--

-- Dumping data for table `users`

--

INSERT INTO `users` (`user_id`, `username`, `password`, `name`) VALUES

(2, 'admin', 'admin', 'admin'),

(3, 'user', 'user', 'user');

--

-- Indexes for dumped tables

--

--

-- Indexes for table `users`

--

ALTER TABLE `users`

ADD PRIMARY KEY (`user_id`);

--

-- AUTO_INCREMENT for dumped tables

--

--

-- AUTO_INCREMENT for table `users`

--

ALTER TABLE `users`

MODIFY `user_id` int(11) NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=4;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;

/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;

/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

  1. Create localhost connection: dbcon.php

$con = mysqli_connect("localhost","root","","login");

// Check connection

if (mysqli_connect_errno())

{

echo "Failed to connect to MySQL: " . mysqli_connect_error();

}

?>

  1. Create a session file: session.php

//Start session

session_start();

//Check whether the session variable SESS_MEMBER_ID is present or not

if (!isset($_SESSION['user_id']) || (trim($_SESSION['user_id']) == '')) {

header("location: index.php");

exit();

}

$session_id=$_SESSION['user_id'];

?>

  1. Create a file CSS style: style.css.

Run your files by localhost: http://localhost/project_name/register.php

Create main page: index.php

  1. Create links page after successful logged to system: home.php

include('dbcon.php');

include('session.php');

$result=mysqli_query($con, "select * from users where user_id='$session_id'")or die('Error In Session');

$row=mysqli_fetch_array($result);

?>

Welcome:

Log out

  1. Create Logout page: logout.php to destroy user sessions.

session_start();

session_destroy();

header('location:index.php');

?>

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!