An Online Forum php Code i-Discuss
I-Discuss Online forum Code
Download all files Download
Folder Structure
->img
->partial
---->_handlelogin.php
---->_handleSignip.php
---->db_connect.php
---->footer.php
---->header.php
---->loginModal.php
---->logout.php
----->signupModal.php
root
---->about.php
---->contact.php
---->index.php
---->search.php
----->thread.php
---->threadlist.php
Database details in last of the page
_______________________________________________________
1) _handleLogin.php code
<?php
$showError= false;
if($_SERVER["REQUEST_METHOD"] == "POST"){
include 'db_connect.php';
$username=$_POST['username'];
$password=$_POST['password'];
$sql = "SELECT * from `users` where username ='$username'";
$result = mysqli_query($conn, $sql);
$numRows= mysqli_num_rows($result);
if($numRows ==1){
$row = mysqli_fetch_assoc($result);
if(password_verify($password, $row['password'])){
session_start();
$_SESSION['loggedin'] = true;
$_SESSION['username'] = $username;
$_SESSION['sno']=$row['sno'];
echo "LOgged in " .$username;
}
header("Location: /forum/index.php");
// else{
// echo "unable to login";
// }
// //header("Location:/forum/index.php");
}
}
?>
_______________________________________________________
2)_handleSignup.php code
<?php
$showError= false;
if($_SERVER["REQUEST_METHOD"] == "POST"){
include 'db_connect.php';
$username=$_POST['username'];
$password=$_POST['password'];
$cpassword=$_POST['cpassword'];
// check whtere this email exits
$existsSql ="SELECT * FROM `users` WHERE username = '$username'";
$result = mysqli_query($conn,$existsSql);
$numExistRows= mysqli_num_rows($result);
if($numExistRows > 0){
// $exists = true;
$showError="Username is already Exists";
}
else{
//$exists = false;\
if(($password == $cpassword)){
$hash = password_hash($password, PASSWORD_DEFAULT);
$sql = "INSERT INTO `users` ( `username`, `password`, `timestamp`) VALUES ('$username', '$hash', current_timestamp())";
$result = mysqli_query($conn, $sql);
if($result){
$showAlert = true;
header("Location:/forum/index.php?signupsuccess=true");
exit();
}
}
else{
$showError = "Password do not match";
}
}
header("Location:/forum/index.php?signupsuccess=false&error = $showError");
}
?>
_____________________________________________________________________________________________________
3) db_connect.php code
<?php
//Script to connect to database
$servername ='localhost';
$username = 'root';
$password = '';
$database ='idiscuss';
$conn = mysqli_connect($servername,$username,$password,$database);
?>
_______________________________________________________
4) footer.php code
<div class="container-fluid bg-dark text-light">
<p class="text-center py-3 mb-0">I-Discuss -Coding Forums 2021 | All rights Reserved.
</div>
_________________________________________________________________________________
5)header.php code
<?php
session_start();
echo '<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
<a class="navbar-brand" href="/forum">IDiscuss</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
<a class="nav-link" href="/forum">Home <span class="sr-only">(current)</span></a>
</li>
<li class="nav-item">
<a class="nav-link" href="about.php">About</a>
</li>
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarDropdown" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Top Categories
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown">';
$sql = "SELECT category_name,category_id FROM `categories` LIMIT 3";
$result= mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)){
echo ' <a class="dropdown-item" href="threadslist.php?cat_id='.$row['category_id'].'">'.$row['category_name'].'</a>';
}
echo ' <div class="dropdown-divider"></div>
</div>
</li>
<li class="nav-item">
<a class="nav-link" href="contact.php" tabindex="-1">Contact Us</a>
</li>
</ul>
<div class="row mx-2">';
if(isset($_SESSION['loggedin']) && $_SESSION['loggedin']==true){
echo '<form class="form-inline my-2 my-lg-0 method ="get" action="search.php"">
<input class="form-control mr-sm-2" name="search" type="search" placeholder="Search" aria-label="Search">
<button class="btn btn-success my-2 my-sm-0" type="submit">Search</button><p class="text-light my-0 mx-2"> Welcome '.$_SESSION['username'].' </p>
<a href="partials/logout.php" class="btn btn-outline-success ml-2" >Logout</a>
</form>';
}
else{
echo' <form class="form-inline my-2 my-lg-0 method ="get" action="search.php">
<input class="form-control mr-sm-2" type="search" placeholder="Search" name="search" aria-label="Search">
<button class="btn btn-success my-2 my-sm-0" type="submit">Search</button>
</form>
<button class="btn btn-outline-success ml-2" data-toggle="modal" data-target="#loginModal" >Login</button>
<button class="btn btn-outline-success mx-2 "data-toggle="modal" data-target="#signupModal" >Signup</button>';
}
echo' </div>
</div>
</nav>';
include 'partials/loginModal.php';
include 'partials/signupModal.php';
if(isset($_GET['signupsuccess']) && $_GET['signupsuccess'] == "true"){
echo '<div class="alert alert-success alert-dismissible fade show my-0" role="alert">
<strong>Success</strong> You can now login !!!!
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
?>
__________________________________________________________________________________________________-
6)LoginModal.php code
<!-- Button trigger modal -->
<!-- Modal -->
<div class="modal fade" id="loginModal" tabindex="-1" role="dialog" aria-labelledby="loginModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="loginModalLabel">Login to Idiscuss</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="/forum/partials/_handleLogin.php" method="post">
<div class="form-group">
<label for="username">Username</label>
<input type="text" class="form-control" id="username" name="username" >
<!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small> -->
</div>
<div class="form-group">
<label for="password">Password</label>
<input type="password" class="form-control" id="password" name="password" placeholder="Password">
</div>
<button type="submit" class="btn btn-primary">Log In</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
_________________________________________________________________________________________________
7)logout.php code
<?php
session_start();
session_unset();
session_destroy();
header("location:/forum/index.php");
exit;
?>
_________________________________________________________________________________________________
8)SignupModal.php code
<!-- Button trigger modal -->
<!-- Modal -->
<div class="modal fade" id="signupModal" tabindex="-1" role="dialog" aria-labelledby="signupModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="signupModalLabel">SignUp for I-Discuss</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body">
<form action="/forum/partials/_handleSignup.php" method="post">
<div class="form-group">
<label for="exampleInputEmail1">User Name</label>
<input type="text" class="form-control" id="username" name="username" >
<!-- <small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>-->
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="password" name="password" required >
</div>
<div class="form-group">
<label for="exampleInputPassword1">Password</label>
<input type="password" class="form-control" id="cpassword" name="cpassword" required>
</div>
<button type="submit" class="btn btn-primary">SignUp</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
_________________________________________________________________________________________________
9)About.php code
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>i-Discuss -Coding Forums</title>
</head>
<body>
<?php include ('partials/header.php') ?>
<?php include ('partials/footer.php') ?>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
_________________________________________________________________________________________________
10)contact.php code
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>i-Discuss -Coding Forums</title>
</head>
<body>
<?php include ('partials/header.php') ?>
<?php include ('partials/footer.php') ?>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
_________________________________________________________________________________________________
11)Index.php code
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
#ques{
min-height: 762px;
}
</style>
<title>i-Discuss -Coding Forums</title>
</head>
<body>
<?php include ('partials/db_connect.php'); ?>
<?php include ('partials/header.php'); ?>
<!-- Slider start here -->
<div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel">
<ol class="carousel-indicators">
<li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="1"></li>
<li data-target="#carouselExampleIndicators" data-slide-to="2"></li>
</ol>
<div class="carousel-inner">
<div class="carousel-item active">
<img class="d-block w-100" src="img/caru_1.jpg" alt="First slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img/caru_2.jpg" alt="Second slide">
</div>
<div class="carousel-item">
<img class="d-block w-100" src="img/caru_3.jpg" alt="Third slide">
</div>
</div>
<a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev">
<span class="carousel-control-prev-icon" aria-hidden="true"></span>
<span class="sr-only">Previous</span>
</a>
<a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next">
<span class="carousel-control-next-icon" aria-hidden="true"></span>
<span class="sr-only">Next</span>
</a>
</div>
<!-- Category Container start -->
<div class="container my-4" >
<h2 class="text-center my-4 "> iDiscuss - Browse Categories</h2>
<div class="row my-4">
<!-- Fetch all the category -->
<!--use a loop to itertate thorugh categories -->
<?php
$sql ="SELECT * FROM `categories`";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)){
// echo $row['category_id'];
// echo $row['category_name'];
$cat=$row['category_name'];
$desc=$row['category_description'];
$id =$row['category_id'];
echo ' <div class="col-md-4 my-2">
<div class="card" style="width: 18rem;">
<img class="card-img-top" src="https://source.unsplash.com/500x400/?'.$cat.',coding" alt="Card image cap">
<div class="card-body ">
<h5 class="card-title"><a href="threadslist.php?catid=' . $id .'">'.$cat.'</a></h5>
<p class="card-text">'.substr($desc,0,90).'...</p>
<a href="threadslist.php?catid='.$id.'" class="btn btn-primary">View Threads</a>
</div>
</div>
</div> ';
}
?>
</div>
</div>
<?php include ('partials/footer.php') ?>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
_________________________________________________________________________________________________
12)Search.php code
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<title>i-Discuss -Coding Forums</title>
</head>
<body>
<?php include ('partials/db_connect.php'); ?>
<?php include ('partials/header.php'); ?>
<!-- search Result -->
<div class="container my-3" id="maincontainer" style=" min-height: 89vh;">
<h1 class="py-2">Search Results for<em> "<?php echo $_GET['search']?>"</em></h1>
<?php
$noresults=true;
$query =$_GET["search"];
$sql="SELECT * FROM `threads` WHERE match (thread_title,thread_desc) against ('$query')";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)){
$title =$row['thread_title'];
$desc =$row['thread_desc'];
$thread_id =$row['thread_id'];
$url ="thread.php?threadid=".$thread_id;
$noresults=false;
// display serach result
echo '<div class="result">
<h3><a href="'.$url.'" class="text-dark">'.$title.'</a></h3>
<p>'. $desc.'</p>
</div>';
}
if($noresults){
echo '<div class="jumbotron jumbotron-fluid">
<div class="container">
<p class="display-4">No Results Found
<p class="lead">Suggestions:
<ul>
<li>Make sure that all words are spelled correctly</li>
<li>Try Differnt keywords.</li>
<li>Try more generak Keywords.</li>
</ul>
</p>
</div>
</div>';
}
?>
</div>
<?php include ('partials/footer.php') ?>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
_________________________________________________________________________________________________
13)thread.php
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
ques{
min-height: 762px;
}
</style>
<title>i-Discuss -Coding Forums</title>
</head>
<body>
<?php include ('partials/db_connect.php'); ?>
<?php include ('partials/header.php'); ?>
<?php
$id=$_GET['threadid'];
$sql="SELECT * FROM `threads` WHERE thread_id=$id";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)){
$title =$row['thread_title'];
$desc =$row['thread_desc'];
$thread_user_id = $row['thread_user_id'];
//Query the users table to find out the name of op
$sql2="SELECT username FROM `users` where sno=$thread_user_id";
$result2 =mysqli_query($conn,$sql2);
$row2 = mysqli_fetch_assoc($result2);
$posted_by = $row2['username'];
}
?>
<?php
$showAlert = false;
$method = $_SERVER['REQUEST_METHOD'];
if($method=='POST'){
// insert into comment db
$comment = $_POST['comment'];
$comment =str_replace("<", "<", $comment);
$comment =str_replace(">", ">", $comment);
$sno =$_POST['sno'];
$sql="INSERT INTO `comments` ( `thread_id`, `comment_by`, `comment_content`, `comment_time`) VALUES ('$id', '$sno', '$comment', current_timestamp())";
$result = mysqli_query($conn,$sql);
$showAlert = true;
if($showAlert){
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Success</strong>Your Comment has been added.
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
}
?>
<!-- Category Container start -->
<div class="container my-4">
<div class="jumbotron">
<h1 class="display-4"><?php echo $title; ?> </h1>
<p class="lead"><?php echo $desc; ?></p>
<hr class="my-4">
<p>This is a peer to peer forum. No Spam / Advertising / Self-promote in the forums is not allowed. Do not post copyright-infringing material. Do not post “offensive” posts, links or images.</p>
<p> Posted By <em><?php echo $posted_by ?></em></p>
</div>
</div>
<?php
if(isset($_SESSION['loggedin']) && $_SESSION['loggedin']==true){
echo'<div class="container">
<h1 class="py-2">Post a Comment</h1>
<form action="'. $_SERVER["REQUEST_URI"].'" method="post">
<div class="form-group">
<label for="exampleFormControlTextarea1">Type Your Comment</label>
<input type="hidden" name="sno" value="'.$_SESSION["sno"].'">
<textarea class="form-control" id="comment" name="comment" rows="3" required></textarea>
</div>
<button type="submit" class="btn btn-success">Post A comment</button>
</form>';
}
else{
echo '<div class="container">
<h3>Post a comment</h3>
<p class="lead"> You are Not Logged In. Please Login To post Comment</p>
</div>';
}
?>
<div class="container mb-5"style="min-height: 631px;">
<h1 class="py-2">Discussions</h1>
<?php
$id=$_GET['threadid'];
$sql="SELECT * FROM `comments` WHERE thread_id=$id";
$result = mysqli_query($conn,$sql);
$noResult= true;
while($row = mysqli_fetch_assoc($result)){
$noResult= false;
$id=$row['comment_id'];
$content =$row['comment_content'];
$comment_time= $row['comment_time'];
$thread_user_id=$row['comment_by'];
$sql2="SELECT username FROM `users` where sno=$thread_user_id";
$result2 =mysqli_query($conn,$sql2);
$row2 = mysqli_fetch_assoc($result2);
echo '<div class="media my-3">
<img src="img/people.png" width="34px" class="mr-3" alt="Generic placeholder image">
<div class="media-body">
<p class="font-weight-bold my-0">'.$row2['username'].' at '.$comment_time. ' </p>
'.$content . '
</div>
</div>';
}
if($noResult){
echo '<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4">No Comments Found</h1>
<p class="lead">Be The First Person To Comment</p>
</div>
</div>';
}
?>
</div>
</div>
<style>
* {
margin: 0;
padding: 0;
}
body{
height: 100%;
width: 100%;
}
</style>
<?php include ('partials/footer.php'); ?>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
_________________________________________________________________________________________________
14)Threadslist.php code
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<style>
ques{
min-height: 762px;
}
</style>
<title>i-Discuss -Coding Forums</title>
</head>
<body>
<?php include ('partials/db_connect.php'); ?>
<?php include ('partials/header.php'); ?>
<?php
$id=$_GET['catid'];
$sql="SELECT * FROM `categories` WHERE category_id=$id";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_assoc($result)){
$catname =$row['category_name'];
$catdesc =$row['category_description'];
}
?>
<?php
$showAlert = false;
$method = $_SERVER['REQUEST_METHOD'];
if($method=='POST'){
$th_title = $_POST['title'];
$th_desc = $_POST['desc'];
$th_title =str_replace("<", "<", $th_title);
$th_title =str_replace(">", ">", $th_title);
$th_desc =str_replace("<", "<", $th_desc);
$th_desc =str_replace(">", ">", $th_desc);
$sno =$_POST['sno'];
$sql="INSERT INTO `threads` ( `thread_title`, `thread_desc`, `thread_cat_id`, `thread_user_id`, `timestamp`) VALUES ( '$th_title', '$th_desc', '$id', '$sno', current_timestamp())";
$result = mysqli_query($conn,$sql);
$showAlert = true;
if($showAlert){
echo '<div class="alert alert-success alert-dismissible fade show" role="alert">
<strong>Success</strong>Your Thread has been added ! please wait for community to respond
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>';
}
}
?>
<!-- Category Container start -->
<div class="container my-4">
<div class="jumbotron">
<h1 class="display-4">Welcome To <?php echo $catname; ?> forums</h1>
<p class="lead"><?php echo $catdesc; ?></p>
<hr class="my-4">
<p>This is a peer to peer forum. No Spam / Advertising / Self-promote in the forums is not allowed. Do not post copyright-infringing material. Do not post “offensive” posts, links or images.
</p>
<p class="lead">
<a class="btn btn-success btn-lg" href="#" role="button">Learn more</a>
</p>
</div>
</div>
<?php
if(isset($_SESSION['loggedin']) && $_SESSION['loggedin']==true){
echo'<div class="container">
<h1 class="py-2">Start a Discussion</h1>
<form action="'.$_SERVER["REQUEST_URI"].'" method="post">
<div class="form-group">
<label for="exampleInputEmail1">Thread Title</label>
<input type="text" class="form-control" id="text" name="title" placeholder="Enter Text" required>
<small id="emailHelp" class="form-text text-muted">Keep your title short as possible.</small>
</div>
<input type="hidden" name="sno" value="'.$_SESSION["sno"].'">
<div class="form-group">
<label for="exampleFormControlTextarea1">Elaborate Your Problem</label>
<textarea class="form-control" id="desc" name="desc" rows="3" required></textarea>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
</div>';
}
else{
echo '<div class="container">
<h1>Start A Discussion</h1>
<p class="lead"> You are Not Logged In. Please Login To start Discussion</p>
</div>';
}
?>
<div class="container mb-5 ">
<h1 class="py-2"> Browse Questions</h1>
<?php
$id=$_GET['catid'];
$sql="SELECT * FROM `threads` WHERE thread_cat_id=$id";
$result = mysqli_query($conn,$sql);
$noResult = true;
while($row = mysqli_fetch_assoc($result)){
$noResult= false;
$id=$row['thread_id'];
$title =$row['thread_title'];
$desc =$row['thread_desc'];
$thread_time=$row['timestamp'];
$thread_user_id=$row['thread_user_id'];
$sql2="SELECT username FROM `users` where sno=$thread_user_id";
$result2 =mysqli_query($conn,$sql2);
$row2 = mysqli_fetch_assoc($result2);
echo '<div class="media my-3 container">
<img src="img/people.png" width="34px" class="mr-3">
<div class="media-body">
<h5 class="mt-0"><a class="text-dark" href="thread.php?threadid='.$id.'">'.$title.'</a></h5>
'.$desc . '
</div><p class="font-weight-bold my-0"> Asked by-'.$row2['username']. ' at '.$thread_time. ' </p>
</div>';
}
if($noResult){
echo '<div class="jumbotron jumbotron-fluid">
<div class="container">
<h1 class="display-4">No Threads Found</h1>
<p class="lead">Be The First Person To ask A questions</p>
</div>
</div>';
}
?>
</div>
<style>
* {
margin: 0;
padding: 0;
}
body{
height: 100%;
width: 100%;
}
</style>
<?php include ('partials/footer.php'); ?>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>
_________________________________________________________________________________________________














hello mr anshu can u help me in coding problems
ReplyDeletehiii am ur great fan sir u are awesome
ReplyDeleteJVS Group vape store terdekat lost vape pod vape vape store liquid vape toko vape terdekat harga vape vape pod coil vape mod vape vapor vapor terdekat vapor kecil Vape Store Terdekat vapor blasting vapor adalah vapor murah toko vapor terdekat dari lokasi saya harga vapor vapor storm vapor pod toko vapor terdekat vape store terdekat vape store vape store terdekat dari lokasi saya vape store jakarta vape murah harga vape murah berkualitas mod vape murah pod vape murah vape murah berkualitas vape murah bagus harga vape murah pod kuy pod pod kuy caliburn pod vinci pod kit pod caliburn aflo pod harga pod pod vape aegis pod pod terbaik 2021 pod terbaik pod aegis pod kuy harga pod stick pod drag harga pod kuy foom pod vape pod vinci pod pod murah pod eazy pod adalah relx pod harga pod smok pod drag s lanyard pod liquid yang cocok untuk pod harga pod vinci pod chocolate drag s pod pod smok pod argus cartridge pod drag pod apa itu pod pod aegis boost pod aio pod exceed grip pod vinci pod caliburn g gorilla pod pod oxva pod mod terbaik 2021 cartridge pod kuy pod deddy corbuzier harga pod caliburn cartridge kuy pod
ReplyDelete