Skip to content
pakainfo

Pakainfo

Web Development & Good Online education

  • Home
  • Blog
  • Categories
  • Tools
  • Full Form
  • Guest Post
    • Guest Posting Service
  • Advertise
  • About
  • Contact Us

Vue.js User Signup And Login Authentication Using PHP

June 13, 2018 Pakainfo Programming, Mysql, Mysqli, php, VueJs Leave a comment

Vue.js User Signup And Login Authentication Using PHP

Contents

  • Vue.js User Signup And Login Authentication Using PHP
    • Vue.js User Registration and Sign up with PHP/MySQLi
    • Creating Simple Database using MySql
    • index.php
    • main.js
    • api.php
    • Related posts

In this Post We Will Explain About is Vue.js User Signup And Login Authentication Using PHP 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 Vue.js User Registration/Sign up with PHP Example

In this post we will show you Best way to implement user authentication using Vuejs php mysql, hear for Vuejs insert update delete using php mysqli with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Vue.js User Registration and Sign up with PHP/MySQLi

In this Example,First of all Add or Include External Libs Like as a(jQuery, css etc..), and then create a simple index.php or index.html page.After that crate a simple javascript file like as a index.js or main.js, It is also add your web-application First Header Part to some priority set.After that Include your relevant CSS Class.

Creating Simple Database using MySql

CREATE TABLE `Clients` (
  `clientId` INT(11) NOT NULL AUTO_INCREMENT,
  `email` VARCHAR(150) NOT NULL,
  `password` VARCHAR(50) NOT NULL,
PRIMARY KEY(`clientId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

index.php

<!DOCTYPE html>
<html>
<head>
	<title>Example of the Vue.js simple Registration form with PHP and MySQLi</title>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
<body>
<div class="container">
	<h1 class="page-header text-right">Vue.js Registration with PHP/MySQLi</h1>
	<div id="register">
		<div class="col-xl-4">
 
			<div class="live panel panel-success">
			  	<div class="live panel-heading"><span class="live glyphicon glyphicon-client"></span> Client Registration</div>
			  	<div class="live panel-body">
			    	<label>Client Email:</label>
			    	<input type="text" class="live form-control" ref="email" v-model="dtlRegInfo.email" v-on:keyup="clientKeycheck">
			    	<div class="text-right" v-if="emailErr">
			    		<span style="font-size:13px;">{{ emailErr }}</span>
			    	</div>
			    	<label>client Password:</label>
			    	<input type="password" class="form-control" ref="password" v-model="dtlRegInfo.password" v-on:keyup="clientKeycheck">
			    	<div class="text-right" v-if="passErr">
			    		<span style="font-size:13px;">{{ passErr }}</span>
			    	</div>
			  	</div>
			  	<div class="live panel-footer">
			  		<button class="live btn btn-default btn-block" @click="clientReg();"><span class="live glyphicon glyphicon-check"></span>Registration</button>
			  	</div>
			</div>
 
			<div class="alert alert-danger text-right" v-if="msgError">
				<button type="button" class="close" @click="msgCls();"><span aria-hidden="true">×</span></button>
				<span class="live glyphicon glyphicon-alert"></span> {{ msgError }}
			</div>
 
			<div class="alert alert-success text-right" v-if="msgofSuccess">
				<button type="button" class="close" @click="msgCls();"><span aria-hidden="true">×</span></button>
				<span class="live glyphicon glyphicon-check"></span> {{ msgofSuccess }}
			</div>
 
		</div>
 
		<div class="col-xl-8">
			<h3>Clients Table</h3>
			<table class="table">
				<thead>
					<th>Client ID</th>
					<th>client Email</th>
					<th>client Password</th>
				</thead>
				<tbody>
					<tr v-for="client in Clients">
						<td>{{ client.clientId }}</td>
						<td>{{ client.email }}</td>
						<td>{{ client.password }}</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>
<script src="dir/vue.js"></script>
<script src="dir/axios.js"></script>
<script src="dir/main.js"></script>
</body>
</html>

main.js

var main = new Vue({
	el: '#register',
	data:{
		msgofSuccess: "",
		msgError: "",
		emailErr: "",
		passErr: "",
		Clients: [],
		dtlRegInfo: {email: '', password: ''},
	},
 
	mounted: function(){
		this.getAllClients();
	},
 
	methods:{
		getAllClients: function(){
			axios.get('api.php')
				.then(function(dataRes){
					if(dataRes.data.error){
						main.msgError = dataRes.data.message;
					}
					else{
						main.Clients = dataRes.data.Clients;
					}
				});
		},
 
		clientReg: function(){
			var regForm = main.toFormData(main.dtlRegInfo);
			axios.post('api.php?do_act=register', regForm)
				.then(function(dataRes){
					console.log(dataRes);
					if(dataRes.data.email){
						main.emailErr = dataRes.data.message;
						main.emailFocus();
						main.msgCls();
					}
					else if(dataRes.data.password){
						main.passErr = dataRes.data.message;
						main.emailErr='';
						main.passFocus();
						main.msgCls();
					}
					else if(dataRes.data.error){
						main.msgError = dataRes.data.message;
						main.emailErr='';
						main.passErr='';
					}
					else{
						main.msgofSuccess = dataRes.data.message;
					 	main.dtlRegInfo = {email: '', password:''};
					 	main.emailErr='';
						main.passErr='';
					 	main.getAllClients();
					}
				});
		},
 
		emailFocus: function(){
			this.$refs.email.focus();
		},
 
		passFocus: function(){
			this.$refs.password.focus();
		},
 
		clientKeycheck: function(event) {
       		if(event.key == "Enter"){
         		main.clientReg();
        	}
       	},
 
		toFormData: function(obj){
			var liveFormData = new FormData();
			for(var key in obj){
				liveFormData.append(key, obj[key]);
			}
			return liveFormData;
		},
 
		msgCls: function(){
			main.msgError = '';
			main.msgofSuccess = '';
		}
 
	}
});

api.php

<?php
 
$db_con = new mysqli("localhost", "username", "Your Password", "DataBase Name");
 
if ($db_con->connect_error) {
    die("DataBase Connection failed: " . $db_con->connect_error);
}
 
$res_output = array('error' => false, 'email'=> false, 'password' => false);
 
$do_act = 'read';
 
if(isset($_GET['do_act'])){
	$do_act = $_GET['do_act'];
}
 
 
if($do_act == 'read'){
	$sql = "select * from Clients";
	$query = $db_con->query($sql);
	$Clients = array();
 
	while($row = $query->fetch_array()){
		array_push($Clients, $row);
	}
 
	$res_output['Clients'] = $Clients;
}
 
if($do_act == 'register'){
 
	function checkStr($data) {
	  $data = trim($data);
	  $data = stripslashes($data);
	  $data = htmlspecialchars($data);
	  return $data;
	}
 
	$email = checkStr($_POST['email']);
	$password = checkStr($_POST['password']);
 
	if($email==''){
		$res_output['email'] = true;
		$res_output['message'] = "Client Email is required";
	}
 
	elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
		$res_output['email'] = true;
		$res_output['message'] = "Invalid Client Email Format";
	}
 
	elseif($password==''){
		$res_output['password'] = true;
		$res_output['message'] = "Client Password is required";
	}
 
	else{
		$sql="select * from Clients where email='$email'";
		$query=$db_con->query($sql);
 
		if($query->num_rows > 0){
			$res_output['email'] = true;
			$res_output['message'] = "client Email already exist";
		}
 
		else{
			$sql = "insert into Clients (email, password) values ('$email', '$password')";
			$query = $db_con->query($sql);
 
			if($query){
				$res_output['message'] = "Client Added Successfully";
			}
			else{
				$res_output['error'] = true;
				$res_output['message'] = "Could not add Client";
			}
		}
	}
}
 
$db_con->close();
//simple pass a json format data in php 
header("Content-type: application/json");
echo json_encode($res_output);
die();
?>

User Login in vuejs

Also Read This ๐Ÿ‘‰   vue js Simple Login Form Tutorials

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

Example

I hope you have Got What is Vue.js User Registration/Sign up 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 posts:

  1. Vue.js Simple Login Script using PHP MySQLi Bootstrap
  2. Login Signup with Laravel
  3. Laravel 7 User Login Authentication From Scratch
  4. CodeIgniter Simple User Registration and Login System
laravel 5.4 authentication tutoriallaravel login and registration examplelaravel vue.js authenticationlaravel vuejs loginvue js authentication tutorialvue-auth tutorialvue-authenticate examplevue.js 2 authentication

Post navigation

Previous Post:Insert Data Into Database using Vue.js with PHP Mysql
Next Post:Vue.js Alert popup-Dialog Box using PHP and CSS

Advertise With Us

Increase visibility and sales with advertising. Let us promote you online.
Click Here

Write For Us

Weโ€™re accepting well-written informative guest posts and this is a great opportunity to collaborate.
Submit a guest post to [email protected]
Contact Us

Freelance web developer

Do you want to build a modern, lightweight, responsive website quickly?
Need a Website Or Web Application Contact : [email protected]
Note: Paid Service
Contact Me

Categories

3movierulz (64) Ajax (464) AngularJS (377) ASP.NET (61) Bio (109) Bollywood (108) Codeigniter (175) CSS (98) Earn Money (93) Education (63) Entertainment (130) fullform (87) Google Adsense (64) Highcharts (77) History (40) Hollywood (109) JavaScript (1359) Jobs (42) jQuery (1423) Laravel (1088) LifeStyle (53) movierulz4 (63) Mysql (1035) Mysqli (894) php (2133) Programming (2345) Python (99) Software (178) Software (90) Stories (98) tamilrockers (104) Tamilrockers kannada (64) Tamilrockers telugu (61) Tech (147) Technology (2416) Tips and Tricks (130) Tools (214) Top10 (505) Trading (94) Trending (76) VueJs (250) Web Technology (112) webtools (200) wordpress (166) World (343)

A To Z Full Forms

Access a complete full forms list with the meaning, definition, and example of the acronym or abbreviation.
Click Here
  • Home
  • About Us
  • Terms And Conditions
  • Write For Us
  • Advertise
  • Contact Us
  • Youtube Tag Extractor
  • Info Grepper
  • Guest Posting Sites
  • Increase Domain Authority
  • Social Media Marketing
  • Freelance web developer
  • Tools
Pakainfo 9-OLD, Ganesh Sco, Kothariya Ring Road, Chokadi, Rajkot - 360002 India
E-mail : [email protected]
Pakainfo

ยฉ 2023 Pakainfo. All rights reserved.

Top
Subscribe On YouTube : Download Source Code
We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype Guest Posting Sites