PHP Retype New Password Confirmation Example

Today, We want to share with you PHP Retype New Password Confirmation.
In this post we will show you re type password, hear for Retype PHP New Password Field we will give you demo and example for implement.
In this post, we will learn about send confirmation email after registration in php with an example.

PHP Retype New Password Confirmation Example

There are the Following The simple About Retype New Password using PHP Full Information With Example and source code.This source code can both password verify first before PHP updating the new Retype password on validation.

Making the database connection

db_conn.php

<?php
	$conn = new mysqli('localhost', 'root', 'atmiya25', '[email protected]') or die(mysqli_error());
 
	if(!$conn){
		die("Error: Failed to connect to database");
	}
?>

Making The Interface

index.php

<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="UTF-8" name="viewport" content="width=device-width, initial-scale=1"/>
		<link rel="stylesheet" type="text/css" href="css/bootstrap.css"/>
	</head>
<body>
	<nav class="navbar navbar-default">
		<div class="container-fluid">
			<a class="navbar-brand" href="https://infinityknow.com">infinityknow</a>
</a>		</div>
	</nav>
	<div class="col-md-3"></div>
	<div class="col-md-6 well">
		<h3 class="text-success">PHP - Simple Change Password Repeatation</h3>
		<hr style="border-top:1px dotted #ccc;"/>
		<button type="button" class="btn btn-success" data-toggle="modal" data-target="#form_modal"><span class="glyphicon glyphicon-plus"></span> Add student</button>
		<br /><br />
		<table class="table table-bordered">
			<thead class="alert-info">
				<tr>
					<th>StudentName</th>
					<th>Password</th>
					<th>StudentFirstName</th>
					<th>StudentLastname</th>
					<th>Action</th>
				</tr>
			</thead>
			<tbody style="background-color:#fff;">
				<?php
					require 'db_conn.php';
					$query = $conn->query("SELECT * FROM `student`") or die($conn->error());
					while($read_pass = $query->read_pass_array()){
				?>
					<tr>
						<td><?php echo $read_pass['studentname']?></td>
						<td><?php echo str_replace($read_pass['password'], "********", $read_pass['password'])?></td>
						<td><?php echo $read_pass['studfname']?></td>
						<td><?php echo $read_pass['studlname']?></td>
						<td><button type="button" class="btn btn-warning" data-toggle="modal" data-target="#update_modal<?php echo $read_pass['student_id']?>">Change Password</button></td>
					</tr>
 
					<div class="modal fade" id="update_modal<?php echo $read_pass['student_id']?>" tabindex="-1" role="dialog" aria-hidden="true">
						<div class="modal-dialog" role="document">
							<form action="update_password.php" method="POST" enctype="multipart/form-data">
								<div class="modal-content">
									<div class="modal-body">
										<div class="col-md-2"></div>
										<div class="col-md-8">
											<div class="form-group">
												<label>StudentName</label>
												<input type="hidden" name="student_id" value="<?php echo $read_pass['student_id']?>"/>
												<input class="form-control" type="text" name="studentname" value="<?php echo $read_pass['studentname']?>" required="required" />
											</div>
											<div class="form-group">
												<label>New Password</label>
												<input class="form-control" type="password" maxlength="12" name="uniq_new_pass" required="required"/>
											</div>
											<div class="form-group">
												<label>Repeat Password</label>
												<input class="form-control" type="password" maxlength="12" name="repeatpass" required="required"/>
											</div>
											<div class="form-group">
												<label>Old Password</label>
												<input class="form-control" type="password" maxlength="12" name="oldpass" required="required"/>
											</div>
											<div class="form-group">
												<label>StudentFirstName</label>
												<input class="form-control" type="text" name="studfname" value="<?php echo $read_pass['studfname']?>" required="required"/>
											</div>
											<div class="form-group">
												<label>StudentLastname</label>
												<input class="form-control" type="text" name="studlname" value="<?php echo $read_pass['studlname']?>" required="required"/>
											</div>
										</div>
									</div>
									<div style="clear:both;"></div>
									<div class="modal-footer">
										<button type="button" class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button>
										<button name="update" class="btn btn-success"><span class="glyphicon glyphicon-save"></span> Update</button>
									</div>
								</div>
							</form>
						</div>
					</div>
 
 
 
				<?php
					}
				?>
			</tbody>
		</table>
	</div>
	<div class="modal fade" id="form_modal" tabindex="-1" role="dialog" aria-hidden="true">
		<div class="modal-dialog" role="document">
			<form action="save_student.php" method="POST" enctype="multipart/form-data">
				<div class="modal-content">
					<div class="modal-body">
						<div class="col-md-2"></div>
						<div class="col-md-8">
							<div class="form-group">
								<label>StudentName</label>
								<input class="form-control" type="text" name="studentname" required="required" />
							</div>
							<div class="form-group">
								<label>Password</label>
								<input class="form-control" type="password" maxlength="12" name="password" required="required"/>
							</div>
							<div class="form-group">
								<label>StudentFirstName</label>
								<input class="form-control" type="text" name="studfname" required="required"/>
							</div>
							<div class="form-group">
								<label>StudentLastname</label>
								<input class="form-control" type="text" name="studlname" required="required"/>
							</div>
						</div>
					</div>
					<div style="clear:both;"></div>
					<div class="modal-footer">
						<button type="button" class="btn btn-danger" data-dismiss="modal"><span class="glyphicon glyphicon-remove"></span> Close</button>
						<button name="save" class="btn btn-success"><span class="glyphicon glyphicon-save"></span> Save</button>
					</div>
				</div>
			</form>
		</div>
	</div>
</body>
<script src="js/jquery-3.2.1.min.js"></script>
<script src="js/bootstrap.js"></script>
</html>

Making PHP Query

save_student.php

<?php
	require_once 'db_conn.php';
	if(ISSET($_POST['save'])){
		$studentname = $_POST['studentname'];
		$password = $_POST['password'];
		$studfname = $_POST['studfname'];
		$studlname = $_POST['studlname'];
 
		$conn->query("INSERT INTO `student` VALUES('', '$studfname', '$studlname', '$studentname', '$password')") or die($conn->error());
 
		header('location: index.php');
	}
?>

update_password

update_password.php

<?php
	require_once 'db_conn.php';
 
	if(ISSET($_POST['update'])){
		$student_id = $_POST['student_id'];
		$studentname = $_POST['studentname'];
		$uniq_new_pass = $_POST['uniq_new_pass'];
		$repeatpass = $_POST['repeatpass'];
		$oldpass = $_POST['oldpass'];
		$studfname = $_POST['studfname'];
		$studlname = $_POST['studlname'];
 
		if($uniq_new_pass == $repeatpass){
			$query = $conn->query("SELECT * FROM `student` WHERE `student_id` = '$student_id' && `password` = '$oldpass'") or die($conn->error());
			$valid = $query->num_rows;
 
			if($valid > 0){
				$conn->query("UPDATE `student` SET `studfname` = '$studfname', `studlname` = '$studlname', `studentname` = '$studentname', `password` = '$uniq_new_pass' WHERE `student_id` = '$student_id'") or die($conn->error());
				echo "<script>alert('Student Password updated')</script>";
				echo "<script>window.location = 'index.php'</script>";
			}else{
				echo "<script>alert('Student Password does not match to old password')</script>";
				echo "<script>window.location = 'index.php'</script>";
			}
 
		}else{
			echo "<script>alert('Student Password does not match')</script>";
			echo "<script>window.location = 'index.php'</script>";
		}
	}
?>

jQuery 15 Powerful Tips and Tricks for Developers and Web Designer

Read :

READ :  Best Online Masters Degrees in Norway

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Password and Confirm Password validation using PHP.
I would like to have feedback on my Infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

https://pakainfo.com/

Leave a Reply

Your email address will not be published. Required fields are marked *