How to Make Active or Inactive in PHP With Mysql Database

Why need status active and inactive in PHP?

Making any task, user, or function active or inactive is the most important part and essential feature of any web application or website. It is also known as blocking or unblocking of user accounts. Some times user performs irrelevant activities and the ones required to deactivate his or her account. By doing this we make that user’s status 0 in the database. In this way when the user tries to log in to his or her account, his login activity is failed. Database successfully login only those accounts whose status is 1 in the database table with active PHP. In this way, we can control inappropriate activities.

Here we are providing you 100% working code. Just copy the code and run it on your machine.

Connectivity of Active PHP Web Application

In order to create a PHP active dynamic web application, we need to have tables and databases created in the MySql database. After creating them we need to establish the connection between active PHP web application and MySQL Database.

Every database has a unique username and password to connect the database and manipulate.

$username = “your_name”;

$password = “your_password”;

$database=”your_database”;

$hostname = “localhost”;

mysql_connect()

The mysql_connect() function is used to connect the MySQL database and active PHP web application.

Now, Connect your PHP script to the MySQL database using the mysql_connect function. The first thing to do is connect to the database, the mysql_connect function is used to connect the MySQL database. The mysql_connect function returns a pointer to the database connection, called database handle.

mysql_connect($hostname, $username, $password)

mysql_connect(‘localhost’,’root’,”);

mysql_select_db(‘database’);

Now, these two lines of code finally establish a connection between the active PHP web application and MySql Database.

Run The Code of status active and inactive in PHP-

When you follow the procedure carefully and you are sure about your code then it’s time to check it. You need to create a table in the MySQL database otherwise it will not show anything

Read Also –  How to fetch data from Mysql database

mysql_close() 

It is used to close the connection.

Hostinger Web Hosting

We will Explain How to Make Active or Inactive in PHP With Database.

<?php
mysql_connect('localhost','root','');
mysql_select_db('database');
if(!empty($_GET['status_id'])&&isset($_GET['status_id']))
		{
			$status_id = $_GET['status_id'];
			$status = $_GET['status'];
			$query = "update menus set status = '$status' where id = '$status_id'";
			mysql_query($query);
			header("location:menus.php");
		}
	// Active / De-Active Record
?>
<html>
<head>
<title>Active/Deactive</title>
</head>
<body>
<form method="POST">
<table border="1">
			<?php 
				
				$query = "select * from table";
				$result = mysql_query($query);	
				
				$row = mysql_fetch_assoc($result)
			?>
			
			<tr>	
				
			<th>Items db</th>
				<?php
					$status =  $row['status']; 
					if($status == 1):	
				?>
				<td style="text-align:center;">
					<a href="menus.php?status_id=<?php echo $row['id'];?>&status=0">
						<img src="ok.png" title="Active / Deactivate Record" />
					</a>
				</td>
				<?php else:	?>
				<td style="text-align:center;">
					<a href="menus.php?status_id=<?php echo $row['id'];?>&status=1">
						<img src="cross.png" title="Active / Deactivate Record" />
					</a>
				</td>
				<?php endif; ?>
				</tr>
</table>
</form>
</body>
</hrml>

For all the above data/code to establish on the web, some sort of hosting is required to make your work online for others no matter who is accessing it until or unless the user is legit. Web hosting will bring traffic to your site and more people will learn about your work as well. Moreover, the data at the backend will be provided to you whenever any uses wishes to work on your webpage, so this will obviously enhance productivity. Further, the active and inactive approach is applied so no irrelevant user would be able to do spam work, hence only relevant and legit data will be taken under consideration. So, rightful hosting is required while making websites online on the server, to choose the appropriate one here is the list of Top 10 Web Hosting Companies that are 100% verified and are on the top categories, plus provide absolute amazing services as per the requirements one wishes to have.

Read More on Facebook

Leave a Comment