php

Notes and Practical Projects for learning php while my learning journey

View on GitHub

Forms Data

Submitting data to the same page

?>


---
## Basic input validating 

```php
<?php
// isset() to check if it's available (posted) 
if(isset($_POST['is_submitted'])){
	$minimum = 4; // minimum username and password length 
	$username = $_POST['username'];
	$password = $_POST['userpass'];

	if (strlen($username) < $minimum or strlen($password) < $minimum)
	{
		echo "Invalid Username or password";
	}
	
	$admins = array('admin', 'root', 'John');
	
	if (!in_array($username, $admins)){
		echo "Sorry, you are not an admin.";
	} else{
		echo "Hello, Admin";
	}
}
?>