Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions tamta_mtchedlidze/error.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php
if(count($errors)>0) :?>
<div>
<?php foreach($errors as $error) : ?>
<p><?php echo $error ?> </p>
<?php endforeach ?>
</div>
<?php endif ?>
37 changes: 37 additions & 0 deletions tamta_mtchedlidze/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<!DOCTYPE html>
<head>
<title> registration form </title>
</head>
<body>
<div class="box">
<div class="head">
<h2> Register here</h2>
</div>
<form action="registrationform.php" method="post">
<div>
<label> First name</label>
<input type="text" name="firstname">
</div>
<div>
<label> Last name</label>
<input type="text" name="lastname">
</div>
<div>
<label for="password">Password:</label>
<input type="password" name="password">
</div>
<div>

<form action="upload.php" method="post" enctype="multipart/form-data">
<label>Select Image File:</label>
<input type="file" name="image">
<input type="submit" name="submit" value="Upload">
</form>
</div>
<button type="submit"> Register</button>
<p> Already have an account? <a href="login.php"><i>Log in</i></a></p>
</form>

</div>
</body>
</html>
38 changes: 38 additions & 0 deletions tamta_mtchedlidze/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
session_start();
if(isset($_SESSION[$firstname])){
$_SESSION['msg']='you must log in first to view this page';
header('location:login.php');
}
if(isset($_GET['logout'])){
session_destroy();
unset($_session['username']);
header("location:login.php");
};

<!DOCTYPE html>
<header>
<title> Home Page </title>
</header>
<body>
<h1> This is homepage </h1>
<?php
if(isset($_SESSION['success'])):?>
<div>
<h3>
<?php
echo $_SESSION['success'];
unset($_SESSION['success']);
?>
</h3>
</div>
<?php endif ?>


<?php if(isset($_SESSION['firstname'])) :?>
<h3> Wellcome <strong> <?php echo $_SESSION['firstname']; ?> </strong></h3>
<button> < a href="index.php?logout='1'" </button>
<?php endif ?>
</body>

</html>
31 changes: 31 additions & 0 deletions tamta_mtchedlidze/login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@

<?php include('server.php') ?>
<!DOCTYPE html>
<head>
<title> registration form </title>
</head>
<body>
<div class="box">
<div class="head">
<h2> Register here</h2>
</div>
<form action="login.php" method="post">
<div>
<label> First name</label>
<input type="text" name="firstname" required>
</div>
<div>
<label> Last name</label>
<input type="text" name="lastname" requiered>
</div>
<div>
<label for="password">Password:</label>
<input type="password" name="password" required>
</div>
<button type="submit" name="login_user"> Log in</button>
<p> Don't have an account? <a href="registrationform.php.php"><i>Register here </i></a></p>
</form>

</div>
</body>
</html>
40 changes: 40 additions & 0 deletions tamta_mtchedlidze/registrationform.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php include('server.php') ?>
<!DOCTYPE html>
<head>
<title> registration form </title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="box">
<div class="header">
<h2> Register here</h2>
</div>
<form action="registrationform.php" method="post">
<?php include($errors.php) ?>
<div>
<label> First name</label>
<input type="text" name="firstname" required>
</div>
<div>
<label> Last name</label>
<input type="text" name="lastname" required>
</div>
<div>
<label for="password">Password:</label>
<input type="password" name="password" required>
</div>
<div>

<form action="upload.php" method="post" enctype="multipart/form-data">
<label>Select Image File:</label>
<input type="file" name="image">
<input type="submit" name="submit" value="Upload">
</form>
</div>
<button type="submit" name="reg_user"> Register</button>
<p> Already have an account? <a href="login.php"><i>Log in</i></a></p>
</form>

</div>
</body>
</html>
65 changes: 65 additions & 0 deletions tamta_mtchedlidze/server.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
session_start();
$firstname="";
$lastname="";
$errors=array();

$db=mysqli_connect("localhost","root",'week1and2') or die("could not connect to database");
$firstname=mysqli_real_escape_string($db,$_POST["firstname"]);
$lastname=mysqli_real_escape_string($db,$_POST["lastname"]);
$password=mysqli_real_escape_string($db,$_POST["password"]);


if(empty($firstname)) { array_push($errors,"firstname is required");}
if(empty($lastname)) { array_push($errors,"lastname is required");};
if(empty($password)) { array_push($errors,"password is required");};


// check db for existing user with same username

$user_check_query="SELECT*FROM user WHERE firstname='$firstname' or lastname='$lastname' LIMIT 1 ";
$results=mysqli_query($db,$user_check_query);
$user=mysqli_fetch_assoc($results);
if ($user) {
if($user['firstname']===$firstname){array_push($errors,'firstname already exists');}
if($user['lastname']===$lastname){array_push($errors,'lastname already exists');}
}

if(count($errors)==0){
$password = md5($password);
$query='INSERT INTO week1and2( firstname,lastname, password) values ($firstname,$lastname,$password)';
mysqli_query($db,$query);
$_SESSION['firstname']=$firstname;
$_SESSION['lastname']=$lastname;
$_SESSION['success']='you are now logged in';
header('location:index.php');
}

if(isset($_POST['login_user'])){
$username=mysqli_real_escape_string($db,$_POST['firstname']);
$lastname=mysqli_real_escape_string($db,$_POST['lastname']);
$password=mysqli_real_escape_string($db,$_POST['password']);
if(empty($firstname)){
array_push($errors,'username is required');
}
if(empty($lastname)){
array_push($errors,'lastname is required');
}
if(empty($password)){
array_push($errors,'password is required');
}
if(count($errors)==0){
$password = md5($password);
$query="SELECT * FROM week1and2 WHERE firstname=$firstname AND password=$password ";
$results=mysqli_query($db,$query);
if(mysqli-num-results($results)){
$_SESSION['firstname']=$firstname;
$_SESSION['success']='logged in successfuly ';
header('location:index.php');
}
else{
array_push($errors,"wrong firstname/password");
}
}

}
13 changes: 13 additions & 0 deletions tamta_mtchedlidze/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
.box{
border: 2em;
border-color: aliceblue;
align:center;
background-color: aqua;
}
.header {
color:blue;
font-size: 25em;;
}
*{
background-color: black;
}