Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new forum feature #55

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
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
75 changes: 75 additions & 0 deletions assets/css/forum-style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
th{
background-color: white;
}

.post{
background-color: lightgray;
}

.reply{
background-color: white;
}

body{
background-image: url("assets/img/pastel-background.jpg");
}

h1{
font-family:Arial, Helvetica, sans-serif;
font-weight: lighter;
}

.reply-button{
color: blue;
}

.reply-button:hover{
color: red;
}

.write-button{
background-color: white;
border: none;
color: black;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
}

.write-button:hover{
background-color: black;
color: white;
}

.btnn{
height: 40px;
font-size: 16px;
}

.inputform{
width: 90%;
padding:32px;
background-color: white;
}

.inputform .inputbox{
position: relative;
width: 100%;
font-size: 18px;
}

.inputform .inputbox input,.inputform .inputbox textarea{
width: 100%;
padding: 5px 0;
font-size: 13px;
margin: 10px 0;
border: none;
border-bottom: 2px solid mediumaquamarine;
resize: none;
}

#contents{
overflow: hidden;
}
Binary file added assets/img/pastel-background.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
69 changes: 69 additions & 0 deletions connectDB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php
//run this to create table in database

//Connect DB Server
$servername = "localhost";
$username = "root";
$password = "";

try{
$connection = new PDO("mysql:host=$servername", $username, $password);

$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully <br/>";

//Create DB
$CreateDb = "CREATE DATABASE ForumDB";
$connection->exec($CreateDb);
echo "Database created successfully<br>";

$dbname = "ForumDB";
$connection = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

//Create Table 1
$CreateTbl = "CREATE TABLE Posts (
Post_ID INT(5) NOT NULL AUTO_INCREMENT,
Email VARCHAR(50) NOT NULL,
Title VARCHAR(75) NOT NULL,
Contents VARCHAR(10000) NOT NULL,
Date_Time DATETIME NOT NULL,
PRIMARY KEY (Post_ID)
)";

$connection->exec($CreateTbl);
echo "Table Posts created successfully<br>";

//Create Table 2
$CreateTbl = "CREATE TABLE Reply (
Email VARCHAR(50) NOT NULL,
Contents VARCHAR(10000) NOT NULL,
Date_Time DATETIME NOT NULL,
Post_ID INT(5) NOT NULL AUTO_INCREMENT,
FOREIGN KEY (Post_ID) REFERENCES Posts(Post_ID)
)";

$connection->exec($CreateTbl);
echo "Table Reply created successfully<br>";

//Insert Data into Table 1 (EXAMPLE)
$InsertData = $connection -> exec ("INSERT INTO Posts (Post_ID,Email,Title,Contents,Date_Time) VALUES
(1, '[email protected]', 'X-RAY Diffraction ', 'Anyone can have more explanation about X-RAY Diffraction for me?', '2021-07-25 13:07:44'),
(2, '[email protected]', 'Biology Question', 'Which famous scientist introduced the idea of natural selection?\r\n', '2021-07-25 13:16:47'),
(3, '[email protected]', 'Math Question', 'How to do this question? \r\nSimplify:(4x2 - 2x) - (-5x2 - 8x).', '2021-07-25 13:21:52')");

//Insert Data into Table 2 (EXAMPLE)
$InsertData = $connection -> exec ("INSERT INTO Reply (Email,Contents,Date_Time,Post_ID) VALUES
('[email protected]', 'Charles Darwin. He argued that natural selection explained how a wide variety of life forms developed over time from a single common ancestor.\r\n', '2021-07-25 13:18:20', 2),
('[email protected]', 'XRD is a technique used to find out the nature of the materials as crystalline or amorphous. It will define the quantification of cementitious materials. The XRD analysis is done with an X-ray source of Cu Kα radiation (λ = 1.5406 Ã…). It will analyze and identify the unknown crystalline compounds by Brag Brentano method. The different parameters such as scan step size, collection time, range, X-ray tube voltage and current should be fixed based on the specimens requirement analysis. The standard database (JCPDS database) for XRD pattern is used for phase identification for a large variety of crystalline phases in the concrete specimens.', '2021-07-25 13:19:42', 1),
('[email protected]', 'X-ray diffraction, a phenomenon in which the atoms of a crystal, by virtue of their uniform spacing, cause an interference pattern of the waves present in an incident beam of X rays. The atomic planes of the crystal act on the X rays in exactly the same manner as does a uniformly ruled grating on a beam of light.', '2021-07-25 13:20:09', 1)");

echo "Data inserted successfully<br>";
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}

$conn = null;
?>
95 changes: 95 additions & 0 deletions forum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<html>

<head>
<title> Forum </title>
<link rel="stylesheet" href="assets/css/styles.css" />
<link rel="stylesheet" href="forum-style.css" />

</head>
<body>
<div class="large-wrapper">
<div class="wrapper">
<header>
<nav>
<div class="menu-icon">
<i class="fa fa-bars fa-2x"></i>
</div>
<div class="logo">
<a href="https://webwiznitr.xyz"><img src="assets/img/logo.ico"></a>
</div>
<div class="menu">
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="index.html#aboutid">ABOUT</a></li>
<li><a href="index.html#materialid">MATERIALS</a></li>
<li><a href="forum.php">FORUM</a></li>
<li><a href="https://chat.whatsapp.com/EVROMYW4i163CcMQkW0bmO"><button class="btnn">JOIN US!</button></a></li>
<li>
<button style="display: none;" id="dark" type="button" class="btn btn-outline-dark">
Dark Mode
</button>
</li>
</ul>
</div>
</nav>
</header>
</div>
</div>

<div class="forum_table" style="position: absolute; top: 100; left: 50;">
<h1> Posts in the Forum</h1>
<table cellpadding="4" cellspacing="4">`
<tr>
<th style="width: 300; height: 40;"> AUTHOR </th>
<th style="width: 900; height: 40;"> POSTS </th>
</tr>
<!-- include php file to display posts -->
<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "forumDB";

try{

$connection = new PDO("mysql:host=$servername;dbname=$dbname", $username,$password);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$GetTbl = "Select * from Posts";
$qGetTbl = $connection->query($GetTbl);

while($rGetTbl = $qGetTbl->fetch()){

echo "<tr class=\"post\">";
echo "<td>". $rGetTbl[1] ."</br>[". $rGetTbl[4] ."]</td>";
echo "<td><strong>". $rGetTbl[2] ."</strong><br/>". $rGetTbl[3] ."</br><br/><a href=\"reply-form.php?post_id=$rGetTbl[0]\" title=\"reply post\" class=\"reply-button\"> REPLY TO THIS POST </a></td>";
echo "</tr>";

$GetTbl2 = "Select * from Reply WHERE Post_ID='$rGetTbl[0]'";
$qGetTbl2 = $connection->query($GetTbl2);

while($rGetTbl2 = $qGetTbl2->fetch()){

echo "<tr class=\"reply\"><td></td>";
echo "<td> REPLY BY: ". $rGetTbl2[0] ." [". $rGetTbl2[2] ."]</br></br>";
echo $rGetTbl2[1] ."</td>";
echo "</tr>";
}
}
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>

</table>

<div class="newpost" style="position: absolute; left: 1000;">
<a href="write-form.html" title="write post" class="write-button"> WRITE NEW POST </a>
</div>

</div>
</body>
</html>
2 changes: 2 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
<li><a href="#">HOME</a></li>
<li><a href="#aboutid">ABOUT</a></li>
<li><a href="#materialid">MATERIALS</a></li>
<li><a href="forum.php">FORUM</a></li>
<li><a href="https://chat.whatsapp.com/EVROMYW4i163CcMQkW0bmO"><button class="btnn">JOIN US!</button></a></li>
<li>
<button style="display: none;" id="dark" type="button" class="btn btn-outline-dark">
Expand Down Expand Up @@ -347,6 +348,7 @@ <h6>Daffodil</h6>
<a href="">home</a>
<a href="#aboutid">about us</a>
<a href="#materialid">materials</a>
<a href="forum.php">forum</a>
<a href="#contactid">contact us</a>
</div>
</div>
Expand Down
86 changes: 86 additions & 0 deletions reply-form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<html>

<head>
<title> Forum </title>
<link rel="stylesheet" href="assets/css/styles.css" />
<link rel="stylesheet" href="assets/css/forum-style.css" />

</head>
<body>
<div class="large-wrapper">
<div class="wrapper">
<header>
<nav>
<div class="menu-icon">
<i class="fa fa-bars fa-2x"></i>
</div>
<div class="logo">
<a href="https://webwiznitr.xyz"><img src="assets/img/logo.ico"></a>
</div>
<div class="menu">
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="index.html#aboutid">ABOUT</a></li>
<li><a href="index.html#materialid">MATERIALS</a></li>
<li><a href="forum.php">FORUM</a></li>
<li><a href="https://chat.whatsapp.com/EVROMYW4i163CcMQkW0bmO"><button class="btnn">JOIN US!</button></a></li>
<li>
<button style="display: none;" id="dark" type="button" class="btn btn-outline-dark">
Dark Mode
</button>
</li>
</ul>
</div>
</nav>
</header>
</div>
</div>

<?php
//define the database connection variables
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "forumDB";

try{
//create a connection object
$connection = new PDO("mysql:host=$servername;dbname=$dbname", $username,$password);

//set the PDO error mode to exception
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

//get post_id which fetch from forum.php when the reply button is clicked
$post_id=$_GET['post_id'];

}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>

<div class="inputform" style="position: absolute; top: 100; left: 50;">
<h1> Reply Post</h1><br/><br/>
<form method="post" action="replyDB.php?post_id=<?php echo $post_id ?>" name="reply_post">

<label for="email">Email Address:</label> <br/>
<div class="inputbox">
<input type="email" name="email" placeholder="[email protected]" required />
</div>

<br/><br/>
<label for="contents">Reply Contents:</label> <br/>
<div class="inputbox">
<textarea name="contents" rows="20" placeholder="Write your reply here..."></textarea> <br /> <br />
</div>

<div class="inputbox">
<input type="submit" name="reply" value="Reply Post" style="width: 150;"/>
</div>

</form>
</div>

</body>
</html>
38 changes: 38 additions & 0 deletions replyDB.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

//define the database connection variables
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ForumDB";

try{
//create a connection object
$connection = new PDO("mysql:host=$servername;dbname=$dbname", $username,$password);

//set the PDO error mode to exception
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$_SERVER["REQUEST_METHOD"];

if ($_POST['reply']){

//get post_id from reply-form.php
$post_id=$_GET['post_id'];

$email = $_POST['email'];
$contents = $_POST['contents'];

$InsertData = $connection -> exec ("INSERT INTO Reply (Email,Contents,Date_Time,Post_ID) VALUES
('$email','$contents',NOW(),'$post_id')");

echo "Reply Post successfully.";
}

header( "refresh:1; forum.php" );
}
catch(PDOException $e)
{
echo "Connection failed: " . $e->getMessage();
}
?>
Loading