Write login page using HTML, PHP, and SQL that will take a user name and passwor
ID: 3829320 • Letter: W
Question
Write login page using HTML, PHP, and SQL that will take a user name and password (using HTML forms and check in the orale database if it exists. Assume there is a table in the database that was created using the SQL statement create table admin ( username varchar2(20) PRIMARY KEY, password varchar2(20));
If the username and password that were entered match an entry in the table, then you should automatically go to another .php page you created that says "you logined in sucessfully"
in my program I want it to take the user to the main application which is just a .php file on my server. Thanks I will upvote clear helpful response
Explanation / Answer
<?php
session_start(); $username = $password = $userError = $passError = '';
if(isset($_POST['sub'])){
$username = $_POST['username']; $password = $_POST['password'];
if($username === 'admin' && $password === 'password'){
$_SESSION['login'] = true; header('LOCATION:wherever.php'); die();
}
if($username !== 'admin')$userError = 'Invalid Username';
if($password !== 'password')$passError = 'Invalid Password';
}
echo "<!DOCTYPE html>
<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
<head>
<meta http-equiv='content-type' content='text/html;charset=utf-8' />
<title>Login</title>
<style type='text.css'>
@import common.css;
</style>
</head>
<body>
<form name='input' action='{$_SERVER['PHP_SELF']}' method='post'>
<label for='username'></label><input type='text' value='$username' id='username' name='username' />
<div class='error'>$userError</div>
<label for='password'></label><input type='password' value='$password' id='password' name='password' />
<div class='error'>$passError</div>
<input type='submit' value='Home' name='sub' />
</form>
<script type='text/javascript' src="common.js"></script>
</body>
</html>";
?>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.