How to Set up Expiration on MySql in PHP

Hello Guys! Today’s tutorial is all about How to Set up Expiration on MySql in PHPIn this tutorial you will learn on Set up Expiration on MySql. Setting up Expiration in mysql is a big feature in any system.

So Let’s get started:
1. Open PHPMyAdmin.
2. Create a database and name it as “expired”.
3. Create database connection and save it.
4.Then Create a form name it index.php and put this code

<DOCTYPE html>
<html>
<head>
<title>How to Set up Expiration on MySQL Row in PHP</title>
</head>
<body>
	<h2>Sample Login Table</h2>
	<table border="1">
		<thead>
			<th>UserID</th>
			<th>Username</th>
			<th>Password</th>
			<th>Login Date</th>
			<th>Expiry</th>
			<th>Status</th>
		</thead>
		<tbody>
			<?php
				include('conn.php');
				
				
				$query=$conn->query("select * from `user`");
				while($row=$query->fetch_array()){
					?>
						<tr>
							<td><?php echo $row['userid']; ?></td>
							<td><?php echo $row['username']; ?></td>
							<td><?php echo $row['password']; ?></td>
							<td><?php echo $row['login_date']; ?></td>
							<td>
								<?php
						
									$today=date('Y-m-d H:i:s');
								
									$expire=date('Y-m-d H:i:s', strtotime($row['login_date']. '+3 days'));
									
									if ($today>=$expire){
										
							
										
										$conn->query("update `user` set status='Expire' where userid='".$row['userid']."'");
										echo $expire;
									}
									else{
										echo $expire;
									}
								?>
							</td>
							<td><?php echo $row['status']; ?></td>
						</tr>
					
					<?php 
				}
			
			?>
		</tbody>
	</table>
</body>
</html>

5. Run and test the program.

Sample

If you have any comments or suggestions about How to Set up Expiration on MySql in PHP Please message us directly:

Download Source Code here:

Other Articles you might read also:

Leave a Comment