Hello. Can someone help me on how to put all my premade PHP files in CodeIgniter 3 I'm having trouble on it thanks.
Code:
index.php
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style/style.css">
<title>Login</title>
</head>
<body>
<div class="container">
<div class="box form-box">
<?php
include ("php/config.php");
if(isset($_POST['submit'])) {
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);
$result = mysqli_query($con, "SELECT * FROM users WHERE Email = '$email' AND Password='$password' ") or die("Select Error");
$row = mysqli_fetch_assoc($result);
if (is_array($row) && !empty($row)) {
$_SESSION['valid'] = $row['Email'];
$_SESSION['username'] = $row['Username'];
$_SESSION['age'] = $row['Age'];
$_SESSION['id'] = $row['Id'];
} else {
echo "<div class='message'>
<p>Wrong Username or Password</p>
<div> <br>";
echo "<a href='index.php'><button class = 'btn'>Go Back</button>";
}
if(isset($_SESSION ['valid'])) {
header("Location: home.php");
}
} else {
?>
<header>Login</header>
<form action="" method="post">
<div class="field input">
<label for="email">Email</label>
<input type="text" name="email" id="email" required>
</div>
<div class="field input">
<label for="password">Password</label>
<input type="password" name="password" id="password" required>
</div>
<div class="field">
<input type="submit" name="submit" class="btn" value="Login" required>
</div>
<div class="links">
Don't have an account? <a href="register.php">Sign Up Now</a>
</div>
</form>
</div>
</div>
<?php } ?>
</body>
</html>
register.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style/style.css">
<title>Register</title>
</head>
<body>
<div class="container">
<div class="box form-box">
<?php
include ("php/config.php");
if (isset($_POST['submit'])) {
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$password = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
$birthday = $_POST['birthday'];
$email = $_POST['email'];
$contactnumber = $_POST['contactnumber'];
//verifying the unique email
$verify_query = mysqli_query($con, "SELECT Email FROM users WHERE Email='$email'");
if (mysqli_num_rows($verify_query) !=0) {
echo "<div class='message'>
<p>This email is used, Try another one please!</p>
</div> <br>";
echo "<a href='javascript:self.history.back()'><button class = 'btn'>Go Back</button>";
}
else {
mysqli_query($con, "INSERT INTO users(FirstName, MiddleName, LastName, Username, Password, Birthday, Email, ContactNumber)
VALUES('$firstname', '$middlename', '$lastname', '$username', '$password', '$birthday', '$email', '$contactnumber')")
or die("Error Occurred");
echo "<div class='message'>
<p>Registration Successfully!</p>
</div> <br>";
echo "<a href='index.php'><button class ='btn'>Login now</button>";
}
} else {
?>
<header>Sign Up</header>
<form action="" method="post">
<div class="field input">
<label for="firstname">First Name</label>
<input type="text" name="firstname" id="firstname" autocomplete="off" required>
</div>
<div class="field input">
<label for="middlename">Middle Name</label>
<input type="text" name="middlename" id="middlename" autocomplete="off" required>
</div>
<div class="field input">
<label for="lastname">Last Name</label>
<input type="text" name="lastname" id="lastname" autocomplete="off" required>
</div>
<div class="field input">
<label for="username">Username</label>
<input type="text" name="username" id="username" autocomplete="off" required>
</div>
<div class="field input">
<label for="password">Password</label>
<input type="password" name="password" id="password" autocomplete="off" required>
</div>
<div class="field input">
<label for="confirmpassword">Confirm Password</label>
<input type="password" name="confirmpassword" id="confirmpassword" autocomplete="off" required>
</div>
<div class="field input">
<label for="birthday">Birthday</label>
<input type="date" name="birthday" id="birthday" required>
</div>
<div class="field input">
<label for="email">Email</label>
<input type="text" name="email" id="email" autocomplete="off" required>
</div>
<div class="field input">
<label for="contactnumber">Contact Number</label>
<input type="text" name="contactnumber" id="contactnumber" autocomplete="off" required>
</div>
<div class="field">
<input type="submit" name="submit" class="btn" value="Register">
</div>
<div class="field">
<input type="button" class="btn" value="Back" onclick="window.location.href='index.php'">
</div>
</form>
</div>
<?php } ?>
</div>
</body>
</html>
home.php
<?php
session_start();
include("php/config.php");
if(!isset($_SESSION['valid'])) {
header("Location: index.php");
}
$id = $_SESSION['id'];
$query = mysqli_query($con, "SELECT * FROM users WHERE Id=$id");
if ($query && $result = mysqli_fetch_assoc($query)) {
$res_FirstName = $result['FirstName'];
$res_MiddleName = $result['MiddleName'];
$res_LastName = $result['LastName'];
$res_Birthday = $result['Birthday'];
$res_Email = $result['Email'];
$res_ContactNumber = $result['ContactNumber'];
} else {
echo "No user found for the provided Id.";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style/style.css">
<title>Home</title>
<style>
.main-box {
text-align: center;
}
</style>
</head>
<body>
<div class="nav">
<div class="logo">
<p>Aaron's Project📖</p>
</div>
<div class="right-clicks">
<?php
echo "<a href='edit.php?Id=$id'>Change Profile</a>";
?>
<a href="php/logout.php"><button class="btn">Log Out</button></a>
</div>
</div>
<div class = "full-intro">
<h1 class = "intro">WELCOME!</h1>
<main>
<div class="main-box top">
<div class="top">
<div class="box">
<p>Name: <b><?php echo $res_FirstName . ' ' . $res_MiddleName . ' ' . $res_LastName ?></b></p>
<p>Birthday: <b><?php echo $res_Birthday ?></b></p>
<br>
<p>Contact Details:</p>
<p>Email: <b><?php echo $res_Email ?></b></p>
<p>Contact: <b><?php echo $res_ContactNumber ?></b></p>
</div>
</div>
</div>
</div>
</main>
</body>
</html>
edit.php
<?php
session_start();
include("php/config.php");
if(!isset($_SESSION['valid'])) {
header("Location: index.php");
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style/style.css">
<title>Change Profile</title>
</head>
<body>
<div class="nav">
<div class="logo">
<p><a href="home.php">Aaron's Project📖</a></p>
</div>
<div class="right-clicks">
<a href="#">Change Profile</a>
<a href="php/logout.php"><button class="btn">Log Out</button></a>
</div>
</div>
<div class="container">
<div class="box form-box">
<?php
if (isset($_POST['submit'])) {
$firstname = $_POST['firstname'];
$middlename = $_POST['middlename'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$password = $_POST['password'];
$confirmpassword = $_POST['confirmpassword'];
$birthday = $_POST['birthday'];
$email = $_POST['email'];
$contactnumber = $_POST['contactnumber'];
// Verify if passwords match
if ($password != $confirmpassword) {
echo "<div class='message'><p>Passwords do not match.</p></div>";
} else {
$id = $_SESSION['id'];
$edit_query = mysqli_query($con,"UPDATE users SET FirstName ='$firstname', MiddleName ='$middlename', LastName ='$lastname', Username ='$username', Password ='$password', Birthday ='$birthday', Email ='$email', ContactNumber ='$contactnumber' WHERE Id=$id ") or die("Error Occurred");
if($edit_query) {
echo "<div class='message'><p>Profile Updated!</p></div>";
echo "<a href='home.php'><button class ='btn'>Go Home</button>";
} else {
echo "<div class='message'><p>Error updating profile.</p></div>";
}
}
} else {
$id = $_SESSION['id'];
$query = mysqli_query($con, "SELECT * FROM users WHERE Id=$id");
while($result = mysqli_fetch_assoc($query)) {
$res_FirstName = $result['FirstName'];
$res_MiddleName = $result['MiddleName'];
$res_LastName = $result['LastName'];
$res_Username = $result['Username'];
$res_Birthday = $result['Birthday'];
$res_Email = $result['Email'];
$res_ContactNumber = $result['ContactNumber'];
}
?>
<header>Change Profile</header>
<form action="" method="post">
<div class="field input">
<label for="firstname">First Name</label>
<input type="text" name="firstname" id="firstname" value="<?php echo $res_FirstName; ?>" autocomplete="off" required>
</div>
<div class="field input">
<label for="middlename">Middle Name</label>
<input type="text" name="middlename" id="middlename" value="<?php echo $res_MiddleName; ?>" autocomplete="off" required>
</div>
<div class="field input">
<label for="lastname">Last Name</label>
<input type="text" name="lastname" id="lastname" value="<?php echo $res_LastName; ?>" autocomplete="off" required>
</div>
<div class="field input">
<label for="username">Username</label>
<input type="text" name="username" id="username" value="<?php echo $res_Username; ?>" autocomplete="off" required>
</div>
<div class="field input">
<label for="password">Password</label>
<input type="password" name="password" id="password" autocomplete="off" required>
</div>
<div class="field input">
<label for="confirmpassword">Confirm Password</label>
<input type="password" name="confirmpassword" id="confirmpassword" autocomplete="off" required>
</div>
<div class="field input">
<label for="birthday">Birthday</label>
<input type="date" name="birthday" id="birthday" value="<?php echo $res_Birthday; ?>" required>
</div>
<div class="field input">
<label for="email">Email</label>
<input type="text" name="email" id="email" value="<?php echo $res_Email; ?>" autocomplete="off" required>
</div>
<div class="field input">
<label for="contactnumber">Contact Number</label>
<input type="text" name="contactnumber" id="contactnumber" value="<?php echo $res_ContactNumber; ?>" autocomplete="off" required>
</div>
<div class="field">
<input type="submit" name="submit" class="btn" value="Update" required>
<input type="button" class="btn" value="Back" onclick="window.location.href='home.php'">
</div>
</form>
<?php } ?>
</div>
</div>
</body>
</html>
style.css
@import url('https://fonts.googleapis.com/css2?family=Poppins&display=swap');
* {
padding: 0;
margin: 0;
box-sizing: border-box;
font-family: 'Poppins', sans-serif;
}
body {
background: #e4e9f7;
}
.container {
display: flex;
align-items: center;
justify-content: center;
min-height: 90vh;
}
.box {
background: #fdfdfd;
display: flex;
flex-direction: column;
padding: 25px 25px;
border-radius: 20px;
box-shadow: 0 0 128px 0 rgba(0,0,0,0.1),
0 32px 64px -48px rgba(0,0,0,0.5);
}
.form-box {
width: 450px;
margin: 0px 10px;
}
.form-box header {
font-size: 25px;
font-weight: 600;
padding-bottom: 10px;
border-bottom: 1px solid #e6e6e6;
margin-bottom: 10px;
}
.form-box form .field {
display: flex;
margin-bottom: 10px;
flex-direction: column;
}
.form-box form .input input {
height: 40px;
width: 100%;
font-size: 16px;
padding: 0 10px;
border-radius: 5px;
border: 1px solid #ccc;
outline: none;
}
.btn {
height: 35px;
background: rgba(76, 68, 182, 0.808);
border: 0;
border-radius: 5px;
color: #fff;
font-size: 15px;
cursor: pointer;
transition: all .3s;
margin-top: 10px;
padding: 0px 10px;
}
.btn:hover {
opacity: 0.82;
}
.submit {
width: 100%;
}
.links{
margin-bottom: 15px;
}
/********** Home **********/
.nav {
background: #fff;
display: flex;
flex-direction: row;
justify-content: space-around;
line-height: 60px;
z-index: 100;
}
.logo {
font-size: 25px;
font-weight: 900;
}
.logo a {
text-decoration: none;
color: #000;
}
.right-links a {
padding: 0 10px;
}
main {
display: flex;
align-items: center;
justify-content: center;
margin-top: 60px;
}
.main-box.top {
justify-content: center;
align-items: center;
min-height: 100vh;
}
.main-box.top .top .box {
display: flex;
font-size: 20px; /* Adjust the font size as needed */
text-align: center; /* Align text to the left within the box */
max-width: 600px; /* Set a maximum width for the box */
}
.intro {
text-align: center;
margin-bottom: 20px; /* Adjust the margin as needed */
}
.bottom {
width: 100%;
margin-top: 20px;
}
@media only screen and (max-width:840px) {
.main-box .top {
display: flex;
flex-direction: column;
justify-content: space-between;
}
.top .box {
margin: 10px 10px;
}
.bottom {
margin-top: 0;
}
}
.message {
text-align: center;
background: #f9eded;
padding: 15px 0px;
border: 1px solid #699053;
border-radius: 5px;
margin-bottom: 10px;
color: red;
}
.full-intro {
padding-top: 250px;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.intro {
text-align: center;
margin-bottom: 20px; /* Adjust the margin as needed */
animation: bounce 2s infinite; /* Apply the animation */
}
@keyframes bounce {
0%, 100% {
transform: translateY(0); /* Start and end position (no movement) */
}
50% {
transform: translateY(-10px); /* Bounce up 10 pixels at the midpoint */
}
}
config.php
<?php
$con = mysqli_connect("localhost","root","root","tutorial") or die ("Couldn't connect");
?>
logout.php
<?php
session_start();
session_destroy();
header("Location: ../index.php");
?>
GjCH5Xnz
GjCH5Xnz