Question: I am having trouble with integrating userID into my code, which is in bold below: (Thank You!!!) Database and Sessions Practice Create a simple web

I am having trouble with integrating userID into my code, which is in bold below: (Thank You!!!)

Database and Sessions Practice

Create a simple web form for a login (ask for username and password). Create a simple table in a database that stores userID, username, and password and populate it with at least one valid username and password. When a user submits the login form, check against the database to see if that username exists and if the password matches. If yes, pass the username and userID into the $_SESSION[] array, redirect the user to a new page, and welcome them by displaying their username and userID.

------------------------------------------------------------------------------------------------------------------------------------------------------

index.php

------------------------------------------------------------------------------------------------------------------------------------------------------

session_start(); ?>

login

Login

Enter Username : Enter Password :

------------------------------------------------------------------------------------------------------------------------------------------------------

login.php

------------------------------------------------------------------------------------------------------------------------------------------------------

$username=$_POST['username'];//username $password=$_POST['password'];//password

session_start(); $connect=mysqli_connect("localhost","root","","lab6"); $query = "SELECT * FROM `login_info` WHERE `username`='$username' && `password`='$password'"; $result=mysqli_query($connect, $query); $count=mysqli_num_rows($result); if($count==1) { echo "Login success"; $_SESSION['log']=1; $_SESSION['username'] = $username; header("refresh:2;url=welcome.php"); } else { echo "Please fill proper details"; header("refresh:2;url=index.php"); }

mysqli_close($connect); ?>

------------------------------------------------------------------------------------------------------------------------------------------------------

welcome.php

------------------------------------------------------------------------------------------------------------------------------------------------------

Welcome, Sir!

logout

------------------------------------------------------------------------------------------------------------------------------------------------------

lab6.sql

------------------------------------------------------------------------------------------------------------------------------------------------------

CREATE SCHEMA IF NOT EXISTS `lab6` DEFAULT CHARACTER SET latin1 ; USE `lab6` ;

-- ----------------------------------------------------- -- Table `lab6`.`login_info` -- ----------------------------------------------------- CREATE TABLE IF NOT EXISTS `lab6`.`login_info` ( `userID` int(11) NOT NULL AUTO_INCREMENT, `username` text NOT NULL, `password` text NOT NULL, PRIMARY KEY (`userID`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `login_info` (`userID` ,`username`, `password`) VALUES ('00', 'joc101', '8888');

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!