Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
maniyaom committed Oct 22, 2023
0 parents commit bf43dd6
Show file tree
Hide file tree
Showing 11 changed files with 675 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
60 changes: 60 additions & 0 deletions OtherPages/login.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php
session_start();

// Check if the user is already logged in
if (isset($_SESSION["email_id"])) {
header("Location: welcome.php");
exit();
}
else{
session_destroy();
}
?>

<!DOCTYPE html>
<html>
<head>
<title>Login Page</title>
</head>
<body>
<h2>Login</h2>
<form action="login.php" method="post">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required><br><br>
<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>
<input type="submit" value="Login">
</form>

<?php
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve user input
$email_id = $_POST["email"];
$user_password = $_POST["password"];

include("dbconnection.php");
$conn = establishConnection();
$query = "SELECT EMAIL_ID, PASSWORD FROM USER_DETAILS WHERE EMAIL_ID = '$email_id' AND PASSWORD = '$user_password'";
$result = mysqli_query($conn, $query);

if ($result) {
if (mysqli_num_rows($result) > 0) {
// Redirect to the welcome page if a matching user is found
session_start();
$_SESSION['email_id'] = $email_id;
closeConnection($conn);
header("Location: welcome.php");
exit();
} else {
// Invalid email or password
echo "Invalid Email or Password !!";
}
} else {
// Handle query execution errors
echo "Error: " . mysqli_error($conn);
}
}
?>
</body>
</html>
78 changes: 78 additions & 0 deletions OtherPages/review.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
session_start();
if (!(isset($_SESSION["email_id"]))){
header("Location: login.php");
exit();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Review Us</title>
</head>
<body>
<form action="review.php" method="post">
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" required><br><br>

<label for="lname">Last Name</label>
<input type="text" id="lname" name="lname" required><br><br>

<label for="email">Email</label>
<input type="email" id="email" name="email" required><br><br>

<label for="review-info">Feedback</label>
<textarea name="review-info" id="review-info" cols="30" rows="10"></textarea>

<input type="submit" value="Submit">
</form>
</body>
</html>

<?php
include("dbconnection.php");
function addReview($conn,$first_name,$last_name,$email_id, $review_info)
{
$query = "CREATE TABLE IF NOT EXISTS REVIEW_DETAILS (
Sr_No int(11) AUTO_INCREMENT,
FIRST_NAME varchar(255),
LAST_NAME varchar(255),
EMAIL_ID varchar(255) NOT NULL,
REVIEW_INFO varchar(1000),
PRIMARY KEY (Sr_No,EMAIL_ID)
)";
#FOREIGN KEY (EMAIL_ID) REFERENCES USER_DETAILS(EMAIL_ID)

if (mysqli_query($conn, $query)) {
echo "Table REVIEW_DETAILS created or already exists.";

$query = "INSERT INTO REVIEW_DETAILS (FIRST_NAME, LAST_NAME, EMAIL_ID, REVIEW_INFO) VALUES ('$first_name', '$last_name', '$email_id', '$review_info')";

if (!(isExists($conn, $email_id,"REVIEW_DETAILS"))) {
if (mysqli_query($conn, $query)) {
echo "Review Added Successfully!";
} else {
echo "Error Adding Review: " . mysqli_error($conn);
}
} else {
echo "Error Adding Review : User has Already Reviewed !!";
}
} else {
echo "Error creating table: " . mysqli_error($conn);
}
}

if($_SERVER["REQUEST_METHOD"] == "POST"){
$first_name = $_POST["fname"];
$last_name = $_POST["lname"];
$email_id = $_POST["email"];
$review_info = $_POST["review-info"];

$conn = establishConnection();
addReview($conn,$first_name,$last_name,$email_id, $review_info);
closeConnection($conn);
}
?>
82 changes: 82 additions & 0 deletions OtherPages/signup.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<!DOCTYPE html>
<html>
<head>
<title>Sign Up Page</title>
</head>
<body>
<h2>Sign Up</h2>
<form action="signup.php" method="post">
<label for="fname">First Name</label>
<input type="text" id="fname" name="fname" required><br><br>

<label for="lname">Last Name</label>
<input type="text" id="lname" name="lname" required><br><br>

<label for="birthdate">Birth Date</label>
<input type="date" id="birthdate" name="birthdate" required><br><br>

<label>Gender</label>
<input type="radio" name="gender" id="male" value="Male">Male
<input type="radio" name="gender" id="female" value="Female">Female

<label for="email">Email</label>
<input type="email" id="email" name="email" required><br><br>

<label for="password">Password:</label>
<input type="password" id="password" name="password" required><br><br>

<input type="submit" value="Sign Up">
</form>
</body>
</html>

<?php

include("dbconnection.php");
function createUser($conn,$first_name,$last_name,$birthdate,$gender,$email_id,$user_password)
{
$query = "CREATE TABLE IF NOT EXISTS USER_DETAILS (
Sr_No int(11) AUTO_INCREMENT,
FIRST_NAME varchar(255),
LAST_NAME varchar(255),
BIRTHDATE date,
GENDER varchar(10),
EMAIL_ID varchar(255) NOT NULL,
PASSWORD varchar(255) NOT NULL,
PRIMARY KEY (Sr_No, EMAIL_ID)
)";

if (mysqli_query($conn, $query)) {
echo "Table USER_DETAILS created or already exists.";

$query = "INSERT INTO USER_DETAILS (FIRST_NAME, LAST_NAME, BIRTHDATE, GENDER, EMAIL_ID, PASSWORD) VALUES ('$first_name', '$last_name', '$birthdate', '$gender', '$email_id', '$user_password')";

if (!(isExists($conn, $email_id,"USER_DETAILS"))) {
if (mysqli_query($conn, $query)) {
echo "User Created Successfully!";
closeConnection($conn);
header("Location: login.php");
exit();
} else {
echo "Error creating user: " . mysqli_error($conn);
}
} else {
echo "Error Creating User : User Already Exists !!";
}
} else {
echo "Error creating table: " . mysqli_error($conn);
}
}

if($_SERVER["REQUEST_METHOD"] == "POST"){
$first_name = $_POST["fname"];
$last_name = $_POST["lname"];
$birthdate = $_POST["birthdate"];
$gender = $_POST["gender"];
$email_id = $_POST["email"];
$user_password = $_POST["password"];

$conn = establishConnection();
createUser($conn,$first_name,$last_name,$birthdate,$gender,$email_id,$user_password);
}
?>
38 changes: 38 additions & 0 deletions OtherPages/welcome.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!DOCTYPE html>
<html>

<head>
<title>Welcome</title>
</head>

<body>
<h2>Welcome, User!</h2>

<?php
session_start();
if (isset($_SESSION["email_id"])) {
echo "You are logged in with " . $_SESSION['email_id'];
} else {
// echo "Please Login to your account !!";
header("Location: login.php");
}
?>

<form action="welcome.php" method="post">
<input type="submit" id="logoutBtn" name="logout" value="Logout">
</form>

<?php
// Check if the "Logout" button was clicked
if (isset($_POST["logout"])) {
// Destroy the session to log the user out
session_start();
session_unset();
session_destroy();
// Redirect to the login page or any other desired page
header("Location: login.php");
exit(); // Add exit() to stop further script execution
}
?>
</body>
</html>
42 changes: 42 additions & 0 deletions config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const apiKeyData = [
'pub_31554370e11a6e70b4b2e4a91f27bad8a6828',
'pub_31571add825b1d3e10c9f35e0079f6328d806',
'pub_3157975aa5dfc81c57e1e121f7aaa49af4ce2',
'pub_31580bbb6ba933bead156cf87510ee0aad428',
'pub_31581573ab6880c5f0ae18d6222bf1d779099',
'pub_315828bef552eff31127d1ef65ad0c1af6b61',
'pub_31583a41e1d8b22b6a6163b17887f24f78339',
'pub_31585e4453cb3f957356bcd3a5762886bc6d0',
'pub_31617ef633d57ed52d4bf6e7f08e17740e1de',
'pub_316194ef4c55a469201683e8a35ff44b9a487',
'pub_31620dd02ae2700eb3acaa4669988d65ae000',
'pub_31621668a5c7168c716b068fb7f3fe43a90cf',
'pub_31622c261979ab968e1ee9e265281073322ae',
'pub_31623a3427a984b872db8d780316935285eee',
'pub_316240ed15a9eba2cec320215e8c72a7572bd',
'pub_316265dee848e75eec918f4d1ca03e9916655',
'pub_31627e33577f37445df2f37e5a8867dd94aa8',
'pub_31628b0dc9d42dc3ef579a68c92b30b02bace',
'pub_316294b354db64a154c4d8c70d02601fb2f13',
'pub_31630ca4a9b58795e3c25382e81eef7d61885',
'pub_316313df70c0362201587a55f202e52845ead',
'pub_31632ab8c04a7d95513a74fa171c6e70334d5',
'pub_316332a3e9288280f849b27f4b0d074e169c9',
'pub_31634187b76f8f2892eb941c7b2606d979a1a',
'pub_316354226103164584e4f29b1b55a78193bc7',
'pub_3163688629520e7eed0681fe2499602349005',
'pub_31637dc17c3297cdd806571ceb21bf7f98e49',
'pub_316381054bd4d3f4eafe577dbfa73505f0809',
'pub_31639d6a1f9c447aa342ab8bbafa539f18968',
'pub_316407f568fddf00d598805f4760c749c3040',
'pub_3164119889a214fcbce9112e0f527974d91c2',
'pub_31643413c23c5c9cdb53a6f72f184e724583d',
'pub_316445b45a0f2cbf58d30957d6d0c4f0998aa',
'pub_316454f5a8ccf45f6bddcc58c05dc7f94fe87',
'pub_316477a155b985b58907514e0c3ca1e1b4669',
'pub_31648a61ea844598a93110a856ee4c82693cf',
'pub_3164997c65a8eba4ef12d3b3e22c0ce80ac38',
'pub_31650e077a52447585ece890c9324e239a391',
'pub_31651a37d1f40e1da897fa72c86d5fc2319ca',
'pub_31652adc57f4d29c04d572b2df28993453182'
];
32 changes: 32 additions & 0 deletions dbconnection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
function establishConnection()
{
$serverName = "localhost";
$username = "root";
$dbPassword = "";
$databaseName = "news_website";
$conn = new mysqli($serverName, $username, $dbPassword, $databaseName);
if (mysqli_connect_error()) {
die("Connection failed: " . mysqli_connect_error());
}
return $conn;
}

function closeConnection($conn)
{
$conn->close();
}

function isExists($conn, $emailId, $table_name)
{
$emailId = mysqli_real_escape_string($conn, $emailId); // Sanitize input
$query = "SELECT EMAIL_ID FROM $table_name WHERE EMAIL_ID = '$emailId'";
$result = mysqli_query($conn, $query);

if ($result) {
return mysqli_num_rows($result) > 0;
} else {
return false;
}
}
?>
49 changes: 49 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<!-- // function bindData(articles){
// console.log(articles[0].content);
// document.write(articles[0].description);
// }
// let url = 'https://gnews.io/api/v4/search?q=';
// let API_KEY = 'e5ca2f6d205ea50bc4fde627b212ef1f';
// async function fetchNews(query){
// const result = await fetch('https://gnews.io/api/v4/search?q=example&country=india&max=100&apikey=e5ca2f6d205ea50bc4fde627b212ef1f');
// console.log(`${url}${query}&apiKey=${API_KEY}`);
// const data = await result.json();
// console.log(data)
// }
-->

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>News</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="utils.css">
<script src="config.js"></script>
<script defer src="script.js"></script>
</head>
<body>
<nav class="navbar">
<div class="logo">E - News</div>
<div class="nav-links">
<ul>
<li><a href="#">Home</a></li>
<li><a href="#">About Us</a></li>
<li><a href="#">Contact Us</a></li>
<li><a href="#">Review Us</a></li>
</ul>
</div>
<div class="loginBtn">
<button class="btn">Login</button>
<button class="btn" style="margin-right: -80px; margin-left: 20px;">Sign Up</button>
</div>
</nav>

<div class="main">
<!-- Fill using JavaScript -->
</div>
<button class="btn" id="loadMoreBtn" onclick="loadMoreNews(`Business`)">Load More</button>
</body>
</html>
Loading

0 comments on commit bf43dd6

Please sign in to comment.