Topic: Mysql

Vue.js Simple Login Script using PHP MySQLi Bootstrap 0

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

<?php
	session_start();
	if(isset($_SESSION['usermst'])){
		header('location:success.php');
	}
?>
<!DOCTYPE html>
<html>
<head>
	<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">
</head>
<body>
<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>
			    	<input type="text" class="form-control" v-model="userDetails.uFirstName" v-on:keyup="allKeyMonitor">
			    	<label>Password:</label>
			    	<input type="password" class="form-control" v-model="userDetails.password" v-on:keyup="allKeyMonitor">
			  	</div>
			  	<div class="panel-footer">
			  		<button class="btn btn-success btn-block" @click="checkLogin();"><span class="live glyphicon glyphicon-log-in"></span> Login</button>
			  	</div>
			</div>
 
			<div class="live alert alert-danger text text-center" v-if="msgError">
				<button type="button" class="close" @click="dataClearMsg();"><span aria-hidden="true">×</span></button>
				<span class="live glyphicon glyphicon-alert"></span> {{ msgError }}
			</div>
 
			<div class="alert alert-success text-center" v-if="msgSuccess">
				<button type="button" class="close" @click="dataClearMsg();"><span aria-hidden="true">×</span></button>
				<span class="glyphicon glyphicon-check"></span> {{ msgSuccess }}
			</div>
 
		</div>
	</div>
</div>
<script src="vue.js"></script>
<script src="axios.js"></script>
<script src="main.js"></script>
</body>
</html>

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

<?php
session_start();
 
$db_con = new mysqli("localhost", "username", "YourPassword", "atmiya");
 
if ($db_con->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

<?php
	session_start();
	$db_con = new mysqli("localhost", "username", "yourpassword", "atmiya");
 
	if ($db_con->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();
 
?>
<!DOCTYPE html>
<html>
<head>
	<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">
</head>
<body>
	<div class="container">
		<div class="live jumbotron">
			<h1 class="text-center">You are most Welcome, <?php echo $row['uFirstName']; ?>!</h1>
			<a href="logout.php" class="btn btn-success"><span class="live glyphicon glyphicon-log-res_Output"></span> Logout</a>
		</div>
	</div>
</body>
</html>

logout.php

<?php
	session_start();
	session_destroy();
	header('location:index.php');
?>

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 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.

Vue.js Alert popup-Dialog Box using PHP and CSS 0

Vue.js Alert popup-Dialog Box using PHP and CSS

Vue.js Alert popup-Dialog Box using PHP and CSS

In this Post We Will Explain About is Vue.js Alert popup-Dialog Box using PHP and CSS 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 How To Create an Alert Message Box Example

In this post we will show you Best way to implement Vue.js Show JavaScript Alert Message Box on ng-click, hear for Fancy Alert and Confirm Box in Vue.js with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Create an Alert using Vue.js with PHP

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

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

style.css

.firstCorn{
	position:absolute;
	top:4px;
	right:6px;
}
.btnClose {
    margin-left: 15px;
    font-size: 18px;
    line-height: 20px;
	color: white;
    font-weight: bold;
    float: right;
    cursor: pointer;
    transition: 0.3s;
}
 
.btnClose:hover {
    color: #c30000;
}
.alert_danger {
    padding: 18px;
    background-color: #3d3d3d;
    color: white;
}
 
.alert_success {
    padding: 15px;
    background-color: #4CAF50;
    color: white;
}

index.php

<!DOCTYPE html>
<html>
<head>
	<title>Make simple an Alert using Vue.js with PHP</title>
3.3.7/css/bootstrap.min.css
2.5.10/vue.min.js
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div id="alert">
	<div class="firstCorn alert_danger" v-if="liveErr">
		<span class="btnClose" @click="dataclsMsg();">×</span>
		<span class="live glyphicon glyphicon-alert"></span> {{ getresMsg }}
	</div>
	<div class="firstCorn alert_success" v-if="liveSucc">
		<span class="btnClose" @click="dataclsMsg();">×</span>
		<span class="live glyphicon glyphicon-check-square-o"></span> {{ getresMsg }}
	</div>
	<div class="container">
		<h1 class="page-header text-center">Create an Alert using Vue.js with PHP</h1>
		<div class="col-md-4">
			<div class="live form-group">
				<label>Student Email:</label>
				<input type="text" class="form-control live" v-model="studentNew.email" v-on:keyup="checkKeyMonitor">
			</div>
			<div class="live form-group">
				<label>Password:</label>
				<input type="text" class="form-control live" v-model="studentNew.password" v-on:keyup="checkKeyMonitor">
			</div>
			<button class="btn btn-primary" @click="addStudent();"><span class="live glyphicon glyphicon-floppy-disk"></span> Save</button> <button class="btn btn-danger" @click="clearForm();"><span class="live glyphicon glyphicon-refresh"></span> Clear</button>
		</div>
		<div class="col-md-8">
			<table class="table">
				<thead>
					<th>student ID</th>
					<th>Student Email</th>
					<th>Student Password</th>
				</thead>
				<tbody>
					<tr v-for="student in students">
						<td>{{ student.studid }}</td>
						<td>{{ student.email }}</td>
						<td>{{ student.password }}</td>
					</tr>
				</tbody>
			</table>
		</div>
	</div>
</div>
<script src="main.js"></script>
</body>
</html>

main.js

var main = new Vue({
	el: '#alert',
	data:{
		studentNew: {email: '', password: ''},
		alertMessage: false,
		liveSucc: false,
		liveErr: false,
		getresMsg: "",
		students: []
	},
 
	mounted: function(){
		this.getStudents();
	},
 
	methods:{
		checkKeyMonitor: function(event) {
       		if(event.key == "Enter"){
         		main.addStudent();
        	}
       	},
 
       	getStudents: function(){
			axios.post('do_action.php')
				.then(function(datares){
					main.students = datares.data.students;
				});
       	},
 
		addStudent: function(){
			var memberForm = main.saveFormData(main.studentNew);
			axios.post('do_action.php?do_action=add', memberForm)
				.then(function(datares){
					console.log(datares);
					if(datares.data.error){
						main.alertMessage = true;
						main.liveErr = true;
						main.liveSucc = false;
						main.getresMsg = datares.data.message;
						setTimeout(function(){
							main.dataclsMsg();
						},3000);
					}
					else{
						main.liveSucc = true;
						main.liveErr = false;
						main.alertMessage = true;
						main.getresMsg = datares.data.message;
						main.studentNew = {email: '', password:''};
						main.getStudents();
						setTimeout(function(){
							main.dataclsMsg();
						},3000);
					}
				});
		},
 
		saveFormData: function(obj){
			var form_data = new FormData();
			for(var key in obj){
				form_data.append(key, obj[key]);
			}
			return form_data;
		},
 
		dataclsMsg: function(){
			main.liveErr = false;
			main.liveSucc = false;
		},
 
		clearForm: function(){
			main.studentNew=main.studentNew = {email: '', password:''};
		}
 
 
 
	}
});

do_action.php

<?php
$db_conn = new mysqli("localhost", "username", "Password", "live24u");
 
if ($db_conn->connect_error) {
    die("Your Db Connection failed: " . $db_conn->connect_error);
}
 
$output = array('error' => false);
 
$do_action="show";
 
if(isset($_GET['do_action'])){
	$do_action=$_GET['do_action'];
}
 
if($do_action=='show'){
	$sql = "select * from students";
	$query = $db_conn->query($sql);
	$students = array();
 
	while($row = $query->fetch_array()){
		array_push($students, $row);
	}
 
	$output['students'] = $students;
}
 
if($do_action=='add'){
	$email=$_POST['email'];
	$password=$_POST['password'];
 
	if($email==''){
		$output['error']=true;
		$output['message']='Add student Failed. Student Name Empty.';
	}
	elseif(!filter_var($email, FILTER_VALIDATE_EMAIL)){
		$output['error']=true;
		$output['message']='Add student Failed. Invalid Email Format';
	}
	elseif($password==''){
		$output['error']=true;
		$output['message']='Add student Failed. Password Empty.';
	}
	elseif(!preg_match("/^[a-zA-Z_1-9]*$/",$password)){
		$output['error']=true;
		$output['message']='Underscore as well as Special Characters  are not allowed in Password';
	}
	else{
		$sql="insert into students (email, password) values ('$email', '$password')";
		$query=$db_conn->query($sql);
 
		if($query){
			$output['message']='student Successfully Added';
		}
		else{
			$output['error']=true;
			$output['message']='Sorry !! Error in Adding Occured';
		}
 
	}
}
 
$db_conn->close();
header("Content-type: application/json");
echo json_encode($output);
die();
 
?>

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 Show JavaScript Alert Message Box on ng-click with Example 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.

Insert Data Into Database using Vue.js with PHP Mysql 0

Insert Data Into Database using Vue.js with PHP Mysql

Insert Data Into Database using Vue.js with PHP Mysql

In this Post We Will Explain About is Insert Data Into Database using Vue.js with PHP Mysql 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 Insert Data into MySQL Database using PHP Example

In this post we will show you Best way to implement insert data into database in vuejs, hear for how to insert data in database using vuejs in php with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Vue.js CRUD Operations with PHP and MySQL

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 Add Modal popup using vuejs

<!-- Vuejs simple Add Modal live24u-->
<div class="liveModal" v-if="displaySimpleModal">
	<div class="lstmodelctn">
		<div class="mdlheader">
			<span class="headerTitle">Add New User</span>
			<button class="closeBtn pull-left" @click="displaySimpleModal = false">×</button>
		</div>
		<div class="mdlBody">
			<div class="form-group live">
				<label>User Firstname:</label>
				<input type="text" class="form-control" v-model="newUser.userfname">
			</div>
			<div class="form-group live">
				<label>User Lastname:</label>
				<input type="text" class="form-control" v-model="newUser.userlname">
			</div>
		</div>
		<hr>
		<div class="mdlFooter">
			<div class="live footerBtn pull-left">
				<button class="live btn btn-default" @click="displaySimpleModal = false"><span class="glyphicon glyphicon-remove"></span> Cancel</button> <button class="btn btn-success live" @click="displaySimpleModal = false; saveUser();"><span class="live glyphicon glyphicon-floppy-disk"></span>USER Save</button>
			</div>
		</div>
	</div>
</div>

style.css

.liveModal{
	position:fixed;
	bottom:0;
	background: rgba(0, 0, 0, 0.4);
	top:0;
	left:0;
	left:0;
}
 
.lstmodelctn{
	width: 800px;
	background: #3d3d3d;
	margin:auto;
	margin-top:52px;
}
 
.mdlheader{
	font-size:20px;
	padding-left:14px;
	padding:12px;
	background: #008852;
	color: #FFFFFF;
	height:52px;
}
 
 
.mdlBody{
	padding:38px;
}
 
.mdlFooter{
	height:39px;
}
 
.footerBtn{
	margin-left:11px;
	margin-top:-9px;
}
 
.closeBtn{
	background: #c60000;
	color: #3d3d3d;
	border:none;
}

Updating index.php

<!DOCTYPE html>
<html>
<head>
	<title>Vue.js simple step by step CRUD Operation using PHP and MySQLi</title>
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
	<h1 class="page-header text-center">simple Vue.js Insert update delete  Operation with PHP and MySQLi</h1>
	<div id="users">
		<div class="col-md-8 col-md-offset-2">
			<div class="row">
				<div class="col-md-12">
					<h2>User List
					<button class="btn btn-success pull-left" @click="displaySimpleModal = true"><span class="live glyphicon glyphicon-plus"></span> User</button>
					</h2>
				</div>
			</div>
 
			<div class="alert alert-danger text-center" 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-center" v-if="msgSuccess">
				<button type="button" class="close" @click="msgCls();"><span aria-hidden="true">×</span></button>
				<span class="live glyphicon glyphicon-ok"></span> {{ msgSuccess }}
			</div>
 
			<table class="table table-bordered table-striped">
				<thead>
					<th>User Firstname</th>
					<th>User Lastname</th>
					<th>User Action</th>
				</thead>
				<tbody>
					<tr v-for="user in users">
						<td>{{ user.userfname }}</td>
						<td>{{ user.userlname }}</td>
						<td>
							<button class="btn btn-success"><span class="live glyphicon glyphicon-edit"></span> Edit</button> <button class="btn btn-danger"><span class="live glyphicon glyphicon-trash"></span> Remove</button>
 
						</td>
					</tr>
				</tbody>
			</table>
		</div>
 
		<?php include('modal.php'); ?>
	</div>
</div>
<script src="vue.js"></script>
<script src="axios.js"></script>
<script src="main.js"></script>
</body>
</html>

Add API(api.php)

if($crud == 'create'){
 
	$userfname = $_POST['userfname'];
	$userlname = $_POST['userlname'];
 
	$sql = "insert into users (userfname, userlname) values ('$userfname', '$userlname')";
	$query = $conn->query($sql);
 
	if($query){
		$resOutput['message'] = "User Added Successfully";
	}
	else{
		$resOutput['error'] = true;
		$resOutput['message'] = "Could not add User";
	}
 
}

Updating our Vue source Code( main.js)

var main = new Vue({
	el: '#users',
	data:{
		displaySimpleModal: false,
		msgError: "",
		msgSuccess: "",
		users: [],
		newUser: {userfname: '', userlname: ''}
	},
 
	mounted: function(){
		this.getAllUsers();
	},
 
	methods:{
		getAllUsers: function(){
			axios.get('api.php')
				.then(function(dataRes){
					//console.log(dataRes);
					if(dataRes.data.error){
						main.msgError = dataRes.data.message;
					}
					else{
						main.users = dataRes.data.users;
					}
				});
		},
 
		saveUser: function(){
			//console.log(main.newUser);
			var memForm = main.toFormData(main.newUser);
			axios.post('api.php?crud=create', memForm)
				.then(function(dataRes){
					//console.log(dataRes);
					main.newUser = {userfname: '', userlname:''};
					if(dataRes.data.error){
						main.msgError = dataRes.data.message;
					}
					else{
						main.msgSuccess = dataRes.data.message
						main.getAllUsers();
					}
				});
		},
 
		toFormData: function(obj){
			var liveFrmDta = new FormData();
			for(var key in obj){
				liveFrmDta.append(key, obj[key]);
			}
			return liveFrmDta;
		},
 
		msgCls: function(){
			main.msgError = '';
			main.msgSuccess = '';
		}
 
	}
});

Vue.js CRUD Operations with PHP and MySQL

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 INSERT DATA INTO DATABASE USING VUEJS AND PHP 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.

Get PHP Session Value using AJAX/Jquery 0

Get PHP Session Value using AJAX/Jquery

Get PHP Session Value using AJAX/Jquery

In this Post We Will Explain About is Get PHP Session Value using AJAX/Jquery 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 how to get session value in jquery ajax Example

In this post we will show you Best way to implement Get variable from PHP file using JQuery/AJAX , hear for javascript variable value stored in php session with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

index.php

<?php
	session_start();
?>
<!DOCTYPE html>
<html>
<head>
	<title>How to Simple get PHP Session Value using jQuery</title>
css/bootstrap.min.css
3.1.0/jquery.min.js
3.3.7/js/bootstrap.min.js
</head>
<body>
<divclass="container">
	<h1 class="page-header text-center">How to get PHP Session Value in jQuery</h1>
	<div class="row">
		<div class="col-xl-6 col-xl-offset-3">
			<h3 class="text-center">Set simple jquery to php Session Value ( $_SESSION['value'] )</h3>
			<form method="POST" action="do_session.php">
				<input type="text" name="set_sessionVal" class="form-control" placeholder="enter simple value" required>
				<div style="margin-top:11px;">
				<button type="submit" class="live btn btn-success">Set Value</button> <a href="logout.php" type="button" class="live btn btn-danger">Remove session Value</a>
				</div>
			</form>
 
			<button type="button" id="checkSession" class="btn btn-success" style="margin-top:30px;">Check Session in jQuery</button>
		</div>
	</div>
 
	<input type="hidden" value="<?php
		if(isset($_SESSION['value'])){
			echo $_SESSION['value'];
		} 
	?>" id="session">
</div>
<script src="session.js"></script>
</body>
</html>

do_session.php

<?php
	session_start();
 
	$set_sessionVal=$_POST['set_sessionVal'];
	$_SESSION['value']=$set_sessionVal;
 
	header('location:index.php');
?>

logout.php

<?php
	session_start();
	unset($_SESSION['value']);
	header('location:index.php');
?>

session.js

$(document).ready(function(){
	//here simple conditions of check session
	$('#checkSession').click(function(){
		var session = $('#session').val();
		if(session == ''){
			alert('Live Session not Set');
			console.log('Live Session not Set');
		}
		else{
			alert('here simple Current Live Session Value: '+session);
			console.log(session);
		}
	});
});

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 Get variable from PHP file using JQuery/AJAX 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.

VueJS CRUD Operations with PHP and MySQLi Example 0

VueJS CRUD Operations with PHP and MySQLi Example

VueJS CRUD Operations with PHP and MySQLi Example

In this Post We Will Explain About is VueJS CRUD Operations with PHP and MySQLi Example 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 Select Insert Update Delete In Php MySQL Example

In this post we will show you Best way to implement Vue.js Update and Delete Data using PHP, hear for VueJS insert, view, edit, delete and update using PHP and Mysql with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Vue.js CRUD Operation 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.

modal.php

<!--Pakainfo.com Edit Modal -->
<div class="myModal" v-if="usershowEditmdl">
	<div class="modalContainer">
		<div class="headerEdit">
			<span class="live headerTitle">Edit User</span>
			<button class="live editCloseBtn pull-right" @click="usershowEditmdl = false">×</button>
		</div>
		<div class="modalBody">
			<div class="live form-group">
				<label>User Firstname:</label>
				<input type="text" class="form-control" v-model="userClick.userfname">
			</div>
			<div class="live form-group">
				<label>User Lastname:</label>
				<input type="text" class="form-control" v-model="userClick.userlname">
			</div>
		</div>
		<hr>
		<div class="modalFooter">
			<div class="footerBtn pull-right">
				<button class="btn btn-default" @click="usershowEditmdl = false"><span class="glyphicon glyphicon-remove"></span> Cancel</button> <button class="btn btn-success" @click="usershowEditmdl = false; updateUser();"><span class="glyphicon glyphicon-check"></span> Save</button>
			</div>
		</div>
	</div>
</div>
 
<!-- Remove Modal -->
<div class="myModal" v-if="showDeleteModal">
	<div class="modalContainer">
		<div class="modelheaderdel">
			<span class="headerTitle">Remove User</span>
			<button class="removeCloseBtn pull-right" @click="showDeleteModal = false">×</button>
		</div>
		<div class="modalBody">
			<h5 class="text-right">You want to Remove User</h5>
			<h2 class="text-right">{{userClick.userfname}} {{userClick.userlname}}</h2>
		</div>
		<hr>
		<div class="modalFooter">
			<div class="footerBtn pull-right">
				<button class="btn btn-default" @click="showDeleteModal = false"><span class="live glyphicon glyphicon-remove"></span> Cancel</button> <button class="live btn btn-danger" @click="showDeleteModal = false; removeUser(); "><span class="live glyphicon glyphicon-trash"></span> Yes</button>
			</div>
		</div>
	</div>
</div>

style.css

.headerEdit{
	height:45px;
	font-size:20px;
	padding-left:18px;
	padding:8px;
	background: #4CAF50;
	color: #c60000;
}
 
.modelheaderdel{
	height:45px;
	font-size:20px;
	padding-left:18px;
	padding:8px;
	background: #3d3d3d;
	color: #c60000;
}
 
.editCloseBtn{
	background: #4CAF50;
	color: #c60000;
	border:none;
}
 
.removeCloseBtn{
	background: #3d3d3d;
	color: #c60000;
	border:none;
}

Updating our index.php

<!DOCTYPE html>
<html>
<head>
	<title>Vue.js Insert, update and delete Operation using PHP/MySQLi</title>
	css/bootstrap.min.css"
	<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class="container">
	<h1 class="page-header text-right">Vue.js Insert Update Delete Operation with PHP/MySQLi</h1>
	<div id="users">
		<div class="col-md-8 col-md-offset-2">
			<div class="row">
				<div class="col-md-12">
					<h2>User List
					<button class="live btn btn-primary pull-right" @click="usershowaddmdl = true"><span class="live glyphicon glyphicon-plus"></span> User</button>
					</h2>
				</div>
			</div>
 
			<div class="live alert alert-danger text-right" v-if="msgError">
				<button type="button" class="close" @click="clsMsg();"><span aria-hidden="true">×</span></button>
				<span class="live glyphicon glyphicon-alert"></span> {{ msgError }}
			</div>
 
			<div class="live alert alert-success text-right" v-if="msgsuccess">
				<button type="button" class="close" @click="clsMsg();"><span aria-hidden="true">×</span></button>
				<span class="live glyphicon glyphicon-ok"></span> {{ msgsuccess }}
			</div>
 
			<table class="table table-bordered table-striped">
				<thead>
					<th>User Firstname</th>
					<th>User Lastname</th>
					<th>Action</th>
				</thead>
				<tbody>
					<tr v-for="user in users">
						<td>{{ user.userfname }}</td>
						<td>{{ user.userlname }}</td>
						<td>
							<button class="btn btn-success" @click="usershowEditmdl = true; selectUser(user);"><span class="glyphicon glyphicon-edit"></span> Edit</button> <button class="btn btn-danger" @click="showDeleteModal = true; selectUser(user);"><span class="glyphicon glyphicon-trash"></span> Remove</button>
 
						</td>
					</tr>
				</tbody>
			</table>
		</div>
 
		<?php include('modal.php'); ?>
	</div>
</div>
<script src="vue.js"></script>
<script src="axios.js"></script>
<script src="main.js"></script>
</body>
</html>

Adding Update and Remove Code in our API

api.php

if($crudopration == 'update'){
 
	$userid = $_POST['userid'];
	$userfname = $_POST['userfname'];
	$userlname = $_POST['userlname'];
 
	$sql = "update users set userfname='$userfname', userlname='$userlname' where userid='$userid'";
	$query = $conn->query($sql);
 
	if($query){
		$out['msg'] = "User Updated Successfully";
	}
	else{
		$out['error'] = true;
		$out['msg'] = "Could not update User";
	}
 
}
 
if($crudopration == 'delete'){
 
	$userid = $_POST['userid'];
 
	$sql = "delete from users where userid='$userid'";
	$query = $conn->query($sql);
 
	if($query){
		$out['msg'] = "User Deleted Successfully";
	}
	else{
		$out['error'] = true;
		$out['msg'] = "Could not delete User";
	}
 
}

Updating our Vue Code

main.js

var main = new Vue({
	el: '#users',
	data:{
		usershowaddmdl: false,
		usershowEditmdl: false,
		showDeleteModal: false,
		msgError: "",
		msgsuccess: "",
		users: [],
		newUser: {userfname: '', userlname: ''},
		userClick: {}
	},
 
	mounted: function(){
		this.getAllUsers();
	},
 
	methods:{
		getAllUsers: function(){
			axios.get('api.php')
				.then(function(results){
					//console.log(results);
					if(results.data.error){
						main.msgError = results.data.msg;
					}
					else{
						main.users = results.data.users;
					}
				});
		},
 
		saveUser: function(){
			//console.log(main.newUser);
			var usrForm = main.myFormData(main.newUser);
			axios.post('api.php?crudopration=create', usrForm)
				.then(function(results){
					//console.log(results);
					main.newUser = {userfname: '', userlname:''};
					if(results.data.error){
						main.msgError = results.data.msg;
					}
					else{
						main.msgsuccess = results.data.msg
						main.getAllUsers();
					}
				});
		},
 
		updateUser(){
			var usrForm = main.myFormData(main.userClick);
			axios.post('api.php?crudopration=update', usrForm)
				.then(function(results){
					//console.log(results);
					main.userClick = {};
					if(results.data.error){
						main.msgError = results.data.msg;
					}
					else{
						main.msgsuccess = results.data.msg
						main.getAllUsers();
					}
				});
		},
 
		removeUser(){
			var usrForm = main.myFormData(main.userClick);
			axios.post('api.php?crudopration=delete', usrForm)
				.then(function(results){
					//console.log(results);
					main.userClick = {};
					if(results.data.error){
						main.msgError = results.data.msg;
					}
					else{
						main.msgsuccess = results.data.msg
						main.getAllUsers();
					}
				});
		},
 
		selectUser(user){
			main.userClick = user;
		},
 
		myFormData: function(obj){
			var dataForm = new FormData();
			for(var key in obj){
				dataForm.append(key, obj[key]);
			}
			return dataForm;
		},
 
		clsMsg: function(){
			main.msgError = '';
			main.msgsuccess = '';
		}
 
	}
});

VueJS INSERT, UPDATE and DELETE

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 Select Insert Update Delete In Php MySQL 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.

PHP – MySQLi Insert Update Delete CRUD Operation using AngularJS 0

PHP - MySQLi Insert Update Delete CRUD Operation using AngularJS

PHP – MySQLi Insert Update Delete CRUD Operation using AngularJS

In this Post We Will Explain About is PHP – MySQLi Insert Update Delete CRUD Operation using AngularJS 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 AngularJS – Insert Update Delete using PHP and MySQL Example

In this post we will show you Best way to implement PHP – OOP CRUD Operation using Angular.js, hear for AngularJS PHP CRUD (Create, Read, Update, Delete) Operations with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

AngularJS CRUD Operation 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

CREATE TABLE `student` (
  `studentId` INT(11) NOT NULL AUTO_INCREMENT,
  `studentfname` VARCHAR(50) NOT NULL,
  `studentlname` VARCHAR(50) NOT NULL,
PRIMARY KEY(`studentId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Creating simple Database Connection

<?php
$db_con = new mysqli("localhost", "username", "Your_Database_Password", "livedbname");
 
if ($db_con->connect_error) {
    die("Connection failed: " . $db_con->connect_error);
}
?>

index.php

<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8"> 
<title>PHP Insert Update Delete CRUD Operation using AngularJS</title>
<link href="<a href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
<div class="container">
	<h1 class="page-header">PHP Insert Update Delete CRUD Operation using AngularJS</h1>
	<div class="row">
		<div ng-app="liveApp" ng-controller="controller" ng-init="displayData()">
			<div class="col-xl-4">
				<form ng-submit="myFunc()">
					<h3>Student Form</h3>
					<hr>
					<div class="live24u form-group">
				    	<label for="studentfname">Firstname</label>
				    	<input type="text" class="live24u form-control" id="studentfname" name="studentfname" ng-model="studentfname" placeholder="Enter Firstname">
				  	</div>
				  	<div class="live24u form-group">
				    	<label for="studentlname">Lastname</label>
				    	<input type="text" class="live24u form-control" id="studentlname" name="studentlname" ng-model="studentlname" placeholder="Enter Lastname">
				  	</div>
				  	<hr>
				  	<button type="submit" class="live24u {{buttonClass}}" ng-click="insert()"><span class="live24u {{mainico}}"></span> {{buttonName}}</button>
				</form>
			</div>
			<div class="col-xl-8">
				<h3>Student List</h3>
				<table class="live table table-bordered dbn table-striped">
					<thead>
						<th>student Firstname</th>
						<th>student Lastname</th>
						<th>Action</th>
					</thead>
					<tbody>
						<tr ng-repeat="stud in student">
							<input type="hidden" value="{{stud.studentId}}">
							<td>{{stud.studentfname}}</td>
							<td>{{stud.studentlname}}</td>
							<td>
								<button class="live btn btn-success" ng-click="update(stud.studentId, stud.studentfname, stud.studentlname)"><span class="live glyphicon glyphicon-pencil"></span> Edit</button> || <button class="live btn btn-danger" ng-click="delete(stud.studentId)"><span class="live glyphicon glyphicon-trash"></span> Delete</button>
							</td>
						</tr>
					</tbody>
				</table>
			</div>
		</div>
	</div>
</div>
<script src="main.js"></script>
</body>
</html>

main.js

var app = angular.module("liveApp", []);
app.controller("controller", function($scope, $http) {
    $scope.buttonName = "Save";
    $scope.mainico = "glyphicon glyphicon-floppy-disk";
    $scope.buttonClass = "btn btn-success";
    $scope.insert = function() {
        if ($scope.studentfname == null) {
            alert("Please input Student Firstname");
        } 
        else if ($scope.studentlname == null) {
            alert("Please input Student Lastname");
        }  
        else {
            $http.post(
                "action.php", {
                    'studentfname': $scope.studentfname,
                    'studentlname': $scope.studentlname,
                    'buttonName': $scope.buttonName,
                    'studentId': $scope.studentId,
                }
            ).success(function(data) {
                alert(data);
                $scope.studentfname = null;
                $scope.studentlname = null;
                $scope.buttonName = "Save";
                $scope.mainico = "glyphicon glyphicon-floppy-disk";
                $scope.buttonClass = "btn btn-success";
                $scope.displayData();
            });
        }
    }
    $scope.displayData = function() {
        $http.get("fetch.php")
            .success(function(data) {
                $scope.student = data;
            });
    }
    $scope.update = function(studentId, studentfname, studentlname) {
        $scope.studentId = studentId;
        $scope.studentfname = studentfname;
        $scope.studentlname = studentlname;
        $scope.mainico = "glyphicon glyphicon-check";
        $scope.buttonClass = "btn btn-success";
        $scope.buttonName = "Update";
    }
    $scope.delete= function(studentId) {
        if (confirm("you want to really delete student?")) {
            $http.post("delete.php", {
                    'studentId': studentId
                })
                .success(function(data) {
                    alert(data);
                    $scope.displayData();
                });
        } else {
            return false;
        }
    }
});

fetch.php

<?php
	include('db_con.php');
	$result = array();
	$query = $db_con->query("select * from student"); 
	if ($query->num_rows > 0) {
	    while ($datarow = $query->fetch_array()) {
	        $result[] = $datarow;
	    }
	    echo json_encode($result);
	}
?>

action.php

<?php
    include('db_con.php');
    $get_data = json_decode(file_get_contents("php://input"));
    if (count($get_data) > 0) {
        $studentfname = mysqli_real_escape_string($db_con, $get_data->studentfname);
        $studentlname = mysqli_real_escape_string($db_con, $get_data->studentlname);
        $actBtnName = $get_data->buttonName;
        if ($actBtnName == "Save") {
            if ($db_con->query("insert into student (studentfname, studentlname) values ('$studentfname', '$studentlname')")) {
                echo "Student Added Successfully";
            } else {
                echo 'Failed';
            }
        }
        if ($actBtnName == "Update") {
            $id    = $get_data->studentId;
            if ($db_con->query("update student set studentfname='$studentfname', studentlname='$studentlname' where studentId='$id'")) {
                echo 'Student Updated Successfully';
            } else {
                echo 'Sorry Failed';
            }
        }
    }
?>

delete.php

<?php
	include('db_con.php');
	$data = json_decode(file_get_contents("php://input"));
	if (count($data) > 0) {
	    $id = $data->studentId;
	    if ($db_con->query("delete from student where studentId='$id'")) {
	        echo 'Student Deleted Successfully';
	    } else {
	        echo 'Failed';
	    }
	}
?>

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 AngularJS CRUD Operations with PHP and MySQL 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.

Create Dynamic Image Fancybox Gallery with jQuery, PHP & MySQL 0

Create Dynamic Image Fancybox Gallery with jQuery, PHP & MySQL

Create Dynamic Image Fancybox Gallery with jQuery, PHP & MySQL

In this Post We Will Explain About is Create Dynamic Image Fancybox Gallery with jQuery, PHP & MySQL 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 Responsive Photo Gallery with jQuery Example

In this post we will show you Best way to implement Creating dynamic Photo Gallery with jQuery, PHP & MySQL, hear for How to Create Dynamic Image Gallery with jQuery, PHP & MySQL with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Creating simple Database

CREATE TABLE `Gallery_photo` (
  `liveImgId` INT(11) NOT NULL AUTO_INCREMENT,
  `information` text NOT NULL,
  `img_location` VARCHAR(150) NOT NULL,
PRIMARY KEY(`liveImgId`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

Include External Libs

<link rel="stylesheet" href="css/bootstrap.min.css" rel="nofollow">
<script src="jquery/3.1.0/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="fancybox/jquery.fancybox.css">
<script src="//code.jquery.com/jquery-3.1.1.min.js"></script>
<script src="fancybox/jquery.fancybox.js"></script>

index.php

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>jquery PHP Gallery using Fancybox Example</title>
	<script type="text/javascript">
	    $("[data-fancybox]").fancybox({ });
	</script>
</head>
<body>
	<div class="container">
		<h1 class="page-header text-center">Fancybox - Fancy jQuery lightbox alternative</h1>
		<h2>
			Photo List
			<a href="#liveaddImg" data-toggle="modal" class="pull-right btn btn-success"><span class="live24u glyphicon glyphicon-plus"></span> Photo</a>
		</h2>
		<?php
			session_start();
 
			if(isset($_SESSION['success'])){
				?>
				<div class="alert alert-success text-center">
					<?php echo $_SESSION['success']; ?>
				</div>
				<?php
 
				unset($_SESSION['success']);
			}
 
			if(isset($_SESSION['galleryError'])){
				?>
				<div class="alert alert-danger text-center">
					<?php echo $_SESSION['galleryError']; ?>
				</div>
				<?php
 
				unset($_SESSION['galleryError']);
			}
		?>
		<table class="table">
			<thead>
				<th>Information</th>
				<th>Gallery Location</th>
				<th>Gallery</th>
			</thead>
			<tbody>
				<?php
					$db_con = new mysqli("localhost", "username", "password", "gallery");
 
					if ($db_con->connect_error) {
					    die("Connection failed: " . $db_con->connect_error);
					}
 
					$sql="select * from Gallery_photo";
					$query=$db_con->query($sql);
					while($datarow=$query->fetch_array()){
						?>
						<tr>
							<td><?php echo $datarow['information']; ?></td>
							<td><?php echo $datarow['img_location']; ?></td>
							<td><a href="<?php echo $datarow['img_location']; ?>" data-fancybox="group" data-caption="<?php echo $datarow["information"]; ?>"><img src="<?php echo $datarow['img_location']; ?>" height="30px" width="30px"></a></td>
						</tr>
						<?php
					}
				?>
			</tbody>
		</table>
	</div>
 
	<!--create / Add Photo -->
	<div class="modal fade" id="liveaddImg" tabindex="-1" role="dialog" aria-labelledby="live_createModel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
					<h4 class="live modal-title text-center" id="live_createModel">Add New Photo</h4>
				</div>
				<div class="live modal-body">
					<div class="live24u container-fluid">
					<form method="POST" action="do_upload.php" enctype="multipart/form-data">
				    	<div class="form-group">
							<div class="row">
					    		<div class="col-xl-2" style="margin-top:8px;">
					    			<label>Description:</label>
					    		</div>
					    		<div class="col-xl-10">
					    			<input type="text" class="form-control" name="information" required>
					    		</div>
					    	</div>
				    	</div>
				    	<div class="live form-group">
				    		<div class="row">
					    		<div class="col-xl-2" >
					    			<label>Gallery Photo:</label>
					    		</div>
					    		<div class="col-xl-10">
					    			<input type="file" name="image">
					    		</div>
					    	</div>
				    	</div>
				    </div>
				</div>
				<div class="live modal-footer">
					<button type="button" class="live24u btn btn-default" data-dismiss="modal"><span class="live glyphicon glyphicon-remove"></span> Cancel</button>
					<button type="submit" class="btn btn-success"><span class="live24u glyphicon glyphicon-floppy-disk"></span> Save</button>
					</form>
				</div>
			</div>
		</div>
	</div>
 
</body>
</html>

do_upload.php

<?php
	session_start();
 
	$db_con = new mysqli("localhost", "username", "yourpassword", "gallery");
	if ($db_con->connect_error) {
	    die("Connection failed: " . $db_con->connect_error);
	}
 
	$information=$_POST['information'];
 
	$getDataInfo = PATHINFO($_FILES["image"]["name"]);
	if (empty($_FILES["image"]["name"])){
		$_SESSION['galleryError']="Upload Failed. Sorry File empty!";
		header('img_location:index.php');
	}
	else{
		if ($getDataInfo['extension'] == "jpg" OR $getDataInfo['extension'] == "jpeg" OR $getDataInfo['extension'] == "png") {
			$newdataFile = $getDataInfo['filename'] . "_" . time() . "." . $getDataInfo['extension'];
			move_uploaded_file($_FILES["image"]["tmp_name"], "upload/" . $newdataFile);
			$img_location = "upload/" . $newdataFile;
 
			$sql="insert into Gallery_photo (information, img_location) values ('$information', '$img_location')";
			$query=$db_con->query($sql);
 
			if($query){
				$_SESSION['success']="Gallery Photo uploaded Successfully Good Lick!";
			}
			else{
				$_SESSION['galleryError']="Something went wrong. Please check to Can't upload Photo!";
			}
 
			header('img_location:index.php');
 
		}
		else{
			$_SESSION['galleryError']="Upload Failed. Sorry Please check upload any format JPG or PNG Gallery_photo only!";
			header('img_location:index.php');
		}
	}
 
?>

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 Fancybox – Fancy jQuery lightbox alternative 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.

How to write SQL Sub Query in PHP with MySQLi 0

How to write SQL Sub Query in PHP with MySQLi

How to write SQL Sub Query in PHP with MySQLi

In this Post We Will Explain About is How to write SQL Sub Query in PHP with 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 SQL subquery with multiple results Example

In this post we will show you Best way to implement SQL Sub Query in PHP/MySQLi, hear for How to write subquery in FROM clause with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Creating Simple Database

CREATE TABLE `students` (
  `studenid` INT(11) NOT NULL AUTO_INCREMENT,
  `studentId` INT(11) NOT NULL,
  `student_post` VARCHAR(200) NOT NULL,
  `studregDate` datetime NOT NULL,
PRIMARY KEY(`studenid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `students` (`studenid`, `studentId`, `student_post`, `studregDate`) VALUES
(1, 1, 'jaydeep Gondaliya', '2018-09-13 08:00:00'),
(2, 1, 'Ankit kathiriya', '2018-10-19 13:30:00'),
(3, 1, 'krunal sisodiya', '2018-10-04 20:05:00'),
(4, 1, 'mayur dhameliya', '2018-10-02 15:10:00'),
(5, 1, 'hitesh dhameliya', '2018-10-15 07:40:00'),
(6, 1, 'chirag dethariya', '2018-09-20 23:00:00'),
(7, 1, 'vivek viradiya', '2018-10-04 01:00:00'),
(8, 1, '#vishal pandya', '2018-09-01 22:05:00');

Creating Simple Connection

<?php
 
$db_con = mysqli_connect("localhost","username","password","crudopet");
if (!$db_con) {
	die("Connection failed: " . mysqli_connect_error());
}
 
?>

Example 1 : table students order by studregDate asc

<?php
	$asc=mysqli_query($db_con,"select * from students order by studregDate asc");
	while($rowasc=mysqli_fetch_array($asc)){
		?>
		<tr>
			<td><?php echo $rowasc['studenid']; ?></td>
			<td><?php echo $rowasc['student_post']; ?></td>
			<td><?php echo date('M-d, Y h:i A',strtotime($rowasc['studregDate'])); ?></td>
		</tr>
		<?php
	}
?>

Example 2 : table students order by studregDate desc

<?php
	$desc=mysqli_query($db_con,"select * from students order by studregDate desc");
	while($rowdesc=mysqli_fetch_array($desc)){
		?>
		<tr>
			<td><?php echo $rowdesc['studenid']; ?></td>
			<td><?php echo $rowdesc['student_post']; ?></td>
			<td><?php echo date('M-d, Y h:i A',strtotime($rowdesc['studregDate'])); ?></td>
		</tr>
		<?php
	}
?>

Example 3 : table students order by studregDate desc limit 3

<?php
	$limit=mysqli_query($db_con,"select * from students order by studregDate desc limit 3");
	while($rowlimit=mysqli_fetch_array($limit)){
		?>
		<tr>
			<td><?php echo $rowlimit['studenid']; ?></td>
			<td><?php echo $rowlimit['student_post']; ?></td>
			<td><?php echo date('M-d, Y h:i A',strtotime($rowlimit['studregDate'])); ?></td>
		</tr>
		<?php
	}
?>

Subquery

<?php
	$sub=mysqli_query($db_con,"select * from (select * from students order by studregDate desc limit 3)as sub left join student on student.studentId=sub.studentId order by studregDate asc");
	while($low_subRow=mysqli_fetch_array($sub)){
		?>
		<tr>
			<td><?php echo $low_subRow['studenid']; ?></td>
			<td><?php echo $low_subRow['studentFname']; ?> <?php echo $low_subRow['studlname']; ?></td>
			<td><?php echo $low_subRow['student_post']; ?></td>
			<td><?php echo date('M-d, Y h:i A',strtotime($low_subRow['studregDate'])); ?></td>
		</tr>
		<?php
	}
?>

index.php

<?php include('db_con.php'); ?>
<!DOCTYPE>
<html>
<head>
<title>Simple SQL SubQuery using PHP with MySQLi</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"" rel="nofollow">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
	<div class="row">
		<h2><center>Simple SQL SubQuery in PHP as well as MySQLi</center></h2>
	</div>
	<div class="row">
		<span>order by studregDate asc</span>
		<table class="table table-bordered">
			<thead>
				<th>StudentID</th>
				<th>Stud Text</th>
				<th>Stud Reg Date</th>
			</thead>
			<tbody>
				<?php
					$asc=mysqli_query($db_con,"select * from students order by studregDate asc");
					while($rowasc=mysqli_fetch_array($asc)){
						?>
						<tr>
							<td><?php echo $rowasc['studenid']; ?></td>
							<td><?php echo $rowasc['student_post']; ?></td>
							<td><?php echo date('M-d, Y h:i A',strtotime($rowasc['studregDate'])); ?></td>
						</tr>
						<?php
					}
				?>
			</tbody>
		</table>
	</div>
	<div class="row">
		<span>order by studregDate desc</span>
		<table class="table table-bordered">
			<thead>
				<th>StudentID</th>
				<th>Stud Text</th>
				<th>Stud Reg Date</th>
			</thead>
			<tbody>
				<?php
					$desc=mysqli_query($db_con,"select * from students order by studregDate desc");
					while($rowdesc=mysqli_fetch_array($desc)){
						?>
						<tr>
							<td><?php echo $rowdesc['studenid']; ?></td>
							<td><?php echo $rowdesc['student_post']; ?></td>
							<td><?php echo date('M-d, Y h:i A',strtotime($rowdesc['studregDate'])); ?></td>
						</tr>
						<?php
					}
				?>
			</tbody>
		</table>
	</div>
	<div class="row">
		<span>Simple order by studregDate desc limit 3</span>
		<table class="table table-bordered>
			<thead>
				<th>StudentID</th>
				<th>Stud Text</th>
				<th>Stud Date</th>
			</thead>
			<tbody>
				<?php
					$limit=mysqli_query($db_con,"select * from students order by studregDate desc limit 3");
					while($rowlimit=mysqli_fetch_array($limit)){
						?>
						<tr>
							<td><?php echo $rowlimit['studenid']; ?></td>
							<td><?php echo $rowlimit['student_post']; ?></td>
							<td><?php echo date('M-d, Y h:i A',strtotime($rowlimit['studregDate'])); ?></td>
						</tr>
						<?php
					}
				?>
			</tbody>
		</table>
	</div>
	<div class="row">
		<span>(order by studregDate desc limit 3) as subquery order by studregDate asc</span>
		<table class="table">
			<thead>
				<th>StudentID</th>
				<th>student</th>
				<th>Stud Text</th>
				<th>Stud Date</th>
			</thead>
			<tbody>
				<?php
					$sub=mysqli_query($db_con,"select * from (select * from students order by studregDate desc limit 3)as sub left join student on student.studentId=sub.studentId order by studregDate asc");
					while($low_subRow=mysqli_fetch_array($sub)){
						?>
						<tr>
							<td><?php echo $low_subRow['studenid']; ?></td>
							<td><?php echo $low_subRow['studentFname']; ?> <?php echo $low_subRow['studlname']; ?></td>
							<td><?php echo $low_subRow['student_post']; ?></td>
							<td><?php echo date('M-d, Y h:i A',strtotime($low_subRow['studregDate'])); ?></td>
						</tr>
						<?php
					}
				?>
			</tbody>
		</table>
	</div>
</div>
</body>
</html>

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 MySQL WHERE Clause with Examples – AND, OR, IN, NOT IN 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.