Commit cb91c82f by mhasan

Functional website, PHP scripts added for registration, login, creating and viewing tasks

parent 293f1740
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href= "css/create_style.css">
<meta charset="UTF-8">
<meta name="description" content="ICD0007 Project, Todo List">
<title> Create List</title>
<?php
session_start();
require "db_conn.php";
$e = NULL;
$dateTime = $_POST['date']. " ". $_POST['time'];
if( isset($_POST['submit']))
{
try
{
/* This will insert Time and to do into a pre existing table called $_POST['user] */
$querry_prep = sprintf("INSERT INTO %s (time, task) VALUES ( :time , :task);",$_SESSION['userName'] );
/* The sprintf part is necessary because there cannot be "quotes" before the table name.*/
/* Be default execute statement adds quotes before and after the bound parameters, so userName couldn't be bound, rather added by sprintf*/
$pdo_st = $pdo -> prepare($querry_prep);
$param = [':time' => $dateTime, ':task' => $_POST['todo'] ];
$pdo_st -> execute($param);
header("location: view.php");
}
catch(PDOException $e)
{
echo("querry error ". $e -> getMessage(). " ". $e -> getLine());
}
}
?>
</head>
<body>
<nav class="nav">
<a href = "index.php"> Index </a> &nbsp; &nbsp;
<a href = "register.php"> Register </a>&nbsp; &nbsp;
<a href = "create.php"> Create List </a>&nbsp; &nbsp;
<a href = "view.php"> View List</a>&nbsp; &nbsp;
<a href = "faq.php"> FAQ </a>&nbsp; &nbsp;
</nav>
<h2> Create List</h2>
<form action = "#" method="POST">
<!-- User Name: <input type="text" name = "user"> <br> <br> unecessary, session variables will hold the username (and table name)-->
Date : <input type="date" name= "date"> <br> <br>
Time : <input type = "time" name ="time"> <br> <br>
Task (upto 300 characters) : <textarea rows = "6" cols= "40" name = "todo" maxlength="300"></textarea> <br> <br>
<input type="submit" name = "submit" value="submit"> <br>
</form>
</body>
</html>
<?php
/*
* This file contains the "common" instructions for connecting to a database.
* Meaning, by including this file a connection to the database has already been made (or a PDO exception, in the event of failiure)
*/
$dsn = "mysql:host=localhost;dbname=project";
$database_user = 'root';
$database_pass = "root";
try
{
$pdo = new PDO($dsn, "root", "root");
$pdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Sets exception parameters
}
catch( PDOException $e)
{
echo(" Connection failed. " . $e -> getMessage() . " ". $e -> getLine() );
}
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href= "css/view.css">
<meta charset="UTF-8">
<meta name="description" content="ICD0007 Project, Todo List">
<title> FAQ</title>
</head>
<body>
<nav class="nav">
<a href = "index.php"> Index </a> &nbsp; &nbsp;
<a href = "register.php"> Register </a>&nbsp; &nbsp;
<a href = "create.php"> Create List </a>&nbsp; &nbsp;
<a href = "view.php"> View List</a>&nbsp; &nbsp;
<a href = "faq.php"> FAQ </a>&nbsp; &nbsp;
</nav>
<h2> Frequently Asked QUestions</h2>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href= "css/index_style.css">
<meta charset="utf-8">
<title>Personal Assistence</title>
<?php
require "db_conn.php";
$e = null;
if(isset($_POST['submit']))
{
try
{
$querry = sprintf("SELECT passHash FROM login WHERE userName = '%s' ;", $_POST['userName']);
$pdo_st = $pdo -> query($querry);
$pdo_st -> setFetchMode(PDO::FETCH_ASSOC);
$array = $pdo_st -> fetch();
$isMatch = password_verify($_POST['pass'], $array['passHash']);
if( $isMatch == TRUE)
{
session_start();
$_SESSION['userName'] = $_POST['userName'];
header("location: create.php"); //redirects user to a certain page upon successful login!
}
}
catch(PDOException $e)
{
echo($e -> getMessage() . " " . $e -> getLine());
}
}
?>
</head>
<body>
<nav class="nav">
<a href = "index.php"> Index </a> &nbsp; &nbsp;
<a href = "register.php"> Register </a>&nbsp; &nbsp;
<a href = "create.php"> Create List </a>&nbsp; &nbsp;
<a href = "view.php"> View List</a>&nbsp; &nbsp;
<a href = "faq.php"> FAQ </a>&nbsp; &nbsp;
</nav>
<h2> WELCOME TO YOUR VERY OWN PERSONAL ASSISTENT</h2>
<p> In modern lifestyle we have to do lot of things, be at different places and communicate with lot of people.
It gets complicated to manage all this. You have to plan your day, week even a month at a time.
<br><b> So join us , manage your day with ease.</b></p>
<form method = "POST" >
<label id="user"> Username:</label>
<input type="text" name = "userName" id = "user">
<br><br>
<label id = "pass"> Password: </label>
<input type="password" name = "pass" id = "pass">
<br><br>
<input type="submit" name = "submit" value = "submit">
</form>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<meta name="description" content="Tallinn University of Technology – Web Technologies - Learning CSS">
<meta name="keywords" content="ICD0007, LAB5, CSS">
<title>Form Validation</title>
<?php
//$form_values = $_POST['salutation'] + '.' + $_POST['f_name'] + ',' + $_POST['mid_name'] + ',' + $_POST['l_name'] + ',' + $_POST['age'] + ',' + $_POST['email'] + ',' + $_POST['tel'] + ',' + $_POST['date'] + ';' ;
//file_put_contents("form.txt", $form_values, FILE_APPEND);
if(is_writable("form.txt"))
{
echo "writeable";
}
else
{
echo "unwriteable";
}
$fptr = fopen('form.txt', 'a+') or die("failure");
$form_values = 'salutations \n';
fwrite($fptr, $form_values);
fclose($fptr);
die("done!");
?>
</head>
<body>
<h2> HTML FORM VALIDATION </h2>
<form method="POST" action=" ">
<select name = "salutation">
<option value = "Mr"> Mr </option>
<option value = "Mrs"> Mrs </option>
<option value = "Dr"> Dr </option>
<option value = "Prof"> Prof </option>
<option value = "Sir"> Sir </option>
</select>
<label for = "first"> First Name </label>
<input type="text" name = "f_name" id = "first" required> <br>
<label for = "middle"> Middle Name </label>
<input type="text" name = "mid_name" id = "middle"> <br>
<label for = "last"> Last Name </label>
<input type="text" name = "l_name" id = "lirst" required> <br>
<label for = "age"> Age </label>
<input type="number" name = "age" label = "age" min = "17" max = "200" required> <br>
<label for = "e"> Email </label>
<input type="email" name = "email" label = "e" required> <br>
<label for = "phone"> Phone </label>
<input type = "tel" name = "tel" label = "phone"> <br>
<label for = "Date"> Date of Arrival </label>
<input type="date" name = "date" label = "Date" required> <br>
<input type="submit" name = "submit"> <br>
</form>
</body>
</html>
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href= "css/register_css.css">
<meta charset="UTF-8">
<meta name="description" content="ICD0007 Project, Todo List">
<title> Registration</title>
<?php
require "db_conn.php";
$e = NULL;
$pass_hash = password_hash($_POST['pass'],PASSWORD_DEFAULT);
if( isset($_POST['submit']))
{
try
{
/* This INSERTS users credentials into the (pre existing)data table called login( userName VARCHAR(20), email VARCHAR(320), passHash CHAR(255));*/
$pdo_stmnt = $pdo -> prepare("INSERT IGNORE INTO login (userName, email, passHash) VALUES( :userName, :email, :passHash);" );
$paramBind = [':userName' => $_POST['u_name'], ':email' => $_POST['email'], ':passHash' => $pass_hash]; //array for the parameters to be bound before execution.
$pdo_stmnt -> execute($paramBind);
/* Creates The data table for the user under the project database. Each time user creats a task, the task will be inserted into the data_table of the user name*/
$querry = sprintf("CREATE TABLE IF NOT EXISTS %s (time DATETIME, task VARCHAR(300) NOT NULL);", $_POST['u_name']);
$pdo -> exec($querry);
}
catch(PDOException $e)
{
echo("querry failiure ". $e -> getMessage(). " ". $e -> getLine());
}
}
?>
</head>
<body>
<nav class="nav">
<a href = "index.php"> Index </a> &nbsp; &nbsp;
<a href = "register.php"> Register </a>&nbsp; &nbsp;
<a href = "create.php"> Create List </a>&nbsp; &nbsp;
<a href = "view.php"> View List</a>&nbsp; &nbsp;
<a href = "faq.php"> FAQ </a>&nbsp; &nbsp;
</nav>
<h2> Registration</h2>
<form action="#" method="post">
User Name &emsp;: <input type="text" name = "u_name"> <br>
Email &emsp;&emsp; &nbsp;&nbsp;&nbsp; : <input type="email" name = "email"> <br>
Password &emsp; &nbsp;&nbsp;: <input type="password" name = "pass"> <br>
Confirm Password : <input type="password"> <br>
<input type="submit" name = "submit" value="submit">
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en-US">
<head>
<link rel="stylesheet" href = "css/view.css">
<meta charset="UTF-8">
<meta name="description" content="ICD0007 Project, Todo List">
<title> View Tasks</title>
<?php
session_start();
require "db_conn.php";
if( isset($_SESSION['userName']) )
{
try
{
$querry = sprintf("SELECT * FROM %s", $_SESSION['userName']);
$pdo_st = $pdo -> query($querry);
$pdo_st -> setFetchMode(PDO::FETCH_ASSOC);
}
catch(PDOException $p)
{
echo($p -> getMessage(). " ". $p -> getLine());
}
}
?>
</head>
<body>
<nav class="nav">
<a href = "index.php"> Index </a> &nbsp; &nbsp;
<a href = "register.php"> Register </a>&nbsp; &nbsp;
<a href = "create.php"> Create List </a>&nbsp; &nbsp;
<a href = "view.php"> View List</a>&nbsp; &nbsp;
<a href = "faq.php"> FAQ </a>&nbsp; &nbsp;
</nav>
<h2> View Tasks for today</h2>
<table>
<tr> <th> TIME</th> <th> TASKS</th></tr>
<?php
while ($row = $pdo_st->fetch()) // Takes 1 row of the data table, stores into an assoc array called row, elements of each row can be called by column name.
{
echo"<tr>";
echo("<td>". $row['time']. "</td>". "<td>". $row['task'] . "</td>");
echo"</tr>";
}
?>
</table>
</body>
</html>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment