Vue.js Simple Login Script using PHP MySQLi Bootstrap

Vue.js Simple Login Script using PHP MySQLi Bootstrap

In this Post We Will Explain About is Vue.js Simple Login with PHP/MySQLi With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to simple login page using Vue.js Example

In this post we will show you Best way to implement simple session with Vue.js and php, hear for Vue.js Login Script using PHP MySQL Bootstrap with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Creating our Database

CREATE TABLE `usermst` (
  `uID` INT(11) NOT NULL AUTO_INCREMENT,
  `uFirstName` VARCHAR(30) NOT NULL,
  `password` VARCHAR(30) NOT NULL,
PRIMARY KEY(`uID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Inserting Data into our Database

INSERT INTO `usermst` (`uID`, `uFirstName`, `password`) VALUES
(1, 'jaydeep', 'Gondaliya'),
(2, 'ankit', 'kathiriya');

index.php




	<title>Simple Example of Vue.js Login with PHP and MySQLi</title>
	<link rel="stylesheet" href="<a href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">


<div class="live container">
	<h1 class="page-header text-center">Simple Example of the Vue.js Login with PHP and MySQLi</h1>
	<div id="login">
		<div class="col-xl-4 col-xl-offset-4">
 
			<div class="panel panel-success">
			  	<div class="panel-heading"><span class="live glyphicon glyphicon-lock"></span> Log in</div>
			  	<div class="panel-body">
			    	<label>UserFirstName:</label>
			    	
			    	<label>Password:</label>
			    	
			  	</div>
			  	<div class="panel-footer">
			  		<button class="btn btn-success btn-block"><span class="live glyphicon glyphicon-log-in"></span> Login</button>
			  	</div>
			</div>
 
			<div class="live alert alert-danger text text-center">
				<button type="button" class="close"><span>×</span></button>
				<span class="live glyphicon glyphicon-alert"></span> {{ msgError }}
			</div>
 
			<div class="alert alert-success text-center">
				<button type="button" class="close"><span>×</span></button>
				<span class="glyphicon glyphicon-check"></span> {{ msgSuccess }}
			</div>
 
		</div>
	</div>
</div>





main.js

var main = new Vue({
	el: '#login',
	data:{
		msgSuccess: "",
		msgError: "",
		userDetails: {uFirstName: '', password: ''},
	},
 
	methods:{
		allKeyMonitor: function(event) {
       		if(event.key == "Enter"){
         		main.checkLogin();
        	}
       	},
 
		checkLogin: function(){
			var logForm = main.toFormData(main.userDetails);
			axios.post('login.php', logForm)
				.then(function(dataRes){
 
					if(dataRes.data.error){
						main.msgError = dataRes.data.message;
					}
					else{
						main.msgSuccess = dataRes.data.message;
						main.userDetails = {uFirstName: '', password:''};
						setTimeout(function(){
							window.location.href="success.php";
						},2000);
 
					}
				});
		},
 
		toFormData: function(obj){
			var form_data = new FormData();
			for(var key in obj){
				form_data.append(key, obj[key]);
			}
			return form_data;
		},
 
		dataClearMsg: function(){
			main.msgError = '';
			main.msgSuccess = '';
		}
 
	}
});

login.php

connect_error) {
    die("Connection failed: " . $db_con->connect_error);
}
 
$res_Output = array('error' => false);
 
$uFirstName = $_POST['uFirstName'];
$password = $_POST['password'];
 
if($uFirstName==''){
	$res_Output['error'] = true;
	$res_Output['message'] = "UserFirstName is required";
}
else if($password==''){
	$res_Output['error'] = true;
	$res_Output['message'] = "Your Password is required";
}
else{
	$sql = "select * from usermst where uFirstName='$uFirstName' and password='$password'";
	$query = $db_con->query($sql);
 
	if($query->num_rows>0){
		$row=$query->fetch_array();
		$_SESSION['usermst']=$row['uID'];
		$res_Output['message'] = "Login Successful";
	}
	else{
		$res_Output['error'] = true;
		$res_Output['message'] = "User Login Failed. User not Found";
	}
}
 
 
 
$db_con->close();
 
header("Content-type: application/json");
echo json_encode($res_Output);
die();
 
 
?>

success.php

connect_error) {
	    die("Connection failed: " . $db_con->connect_error);
	}
 
	if (!isset($_SESSION['usermst']) ||(trim ($_SESSION['usermst']) == '')){
		header('location:index.php');
	}
 
	$sql="select * from usermst where uID='".$_SESSION['usermst']."'";
	$query=$db_con->query($sql);
	$row=$query->fetch_array();
 
?>



	<title>Example of the Vue.js Login with PHP as well as MySQLi demo</title>
	<link rel="stylesheet" href="<a href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">


	<div class="container">
		<div class="live jumbotron">
			<h1 class="text-center">You are most Welcome, !</h1>
			<a href="logout.php" class="btn btn-success"><span class="live glyphicon glyphicon-log-res_Output"></span> Logout</a>
		</div>
	</div>


logout.php

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Read Also:  what does pairwise distinct mean?

Example

I hope you have Got What is Vue.js Simple Login with PHP/MySQLi And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.


Related FAQ

Here are some more FAQ related to this Article:

  1. Read Also:  VueJS Textarea maxLength Remaining Character Count
  2. Read Also:  Vue.js CRUD Example Tutorial For Beginners
  3. Read Also:  find the nth prime number in fastest possible way
  4. Read Also:  Pure CSS Add active class to hover effects
  5. Read Also:  PHP Web Application create Installer scripts
  6. Read Also:  vue js Simple Login Form Tutorials
  7. Read Also:  PHP file_get_contents URL Examples
  8. Read Also:  Laravel 5.7 Route Group Names Example
  9. Read Also:  Retrieve Data From MySQL Database using Vue.js PHP
  10. Read Also:  Create RESTful API using PHP
CLOSEX