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

Master #82

Open
wants to merge 7 commits into
base: master
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
103 changes: 103 additions & 0 deletions answer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
<?php /*
include 'db_connect.php';
// Variable for DB Connection
$servername = "localhost";
$username = "admin";
$password = "root";
$dbname="stackexchange";
$connection = new db_connect($servername, $username, $password, $dbname);
$connection->connect();
$connection->postQuestion($_POST["name"], $_POST["email"], $_POST["questiontopic"],$_POST["content"]);
$connection->close_connection();
*/
?>

<html>
<head>
<Title> Simple StackExchange </Title>
<link rel="stylesheet" href="styles.css" type="text/css">
<meta> </meta>
<script>
//Validate the Form
function validateForm() {
// Alert if the name is empty
var result=true;
var name = document.forms["answerForm"]["name"].value;
if (name == null || name == "") {
alert ("Name must be filled out");
result=false;
}

//alert if the email is empty or is not correct
var email = document.forms["answerForm"]["email"].value;
if (email==null || email=="") {
alert ("Email must be filled out");
result=false;
}
else if (!(/[\w][\@]+[a-z]+[\.]+[\w]/.test(email))) {
alert ("Email must be filled out correctly");
result=false;
}

//Alert if the content of answer is empty
var content = document.forms["answerForm"]["content"].value;
if (content == null || content == "") {
alert ("Content must be filled out");
result=false;
}
return result;
}
</script>
</head>
<body>
<div class="container">
<div class="header">
<h1> Simple Stack Exchange </h1>
</div>

<!--Question Section -->
<div class="question">
<div >
<h3>Question Topic Here
<!--<?php echo $_POST["questiontopic"]?>--></h3>
</div>
<!-- Question content -->
<div>
<!-- Vote Section -->
<div class="vote">

</div>
</div>
<!--Footer content -->
<div>
<!--<p>
<?php /*echo "asked by ", $_POST["username"]," at ", getTimestamp("question", getQuestionId("question", $_POST["username"], $_POST["questiontopic"])); */?> | <a href="#" id="editPost">edit</a> | <a href="#" onclick="" id="deletePost">delete</a> </p>
-->
</div>
</div>
<!-- Answer Section -->
<div class="answer">
<!-- PHP here to print all the answer of the question -->
</div>


<div class="question">
<form action="answer.php" method="post" name="answerForm" onsubmit="return validateForm()">
<div class="textbox">
<!-- Name -->
<input type="text" name="name" placeholder="Name" size="50">
</div>
<div class="textbox">
<!-- Email -->
<input type="text" name="email" placeholder="E-mail" size="50" >
</div>
<div class="textbox">
<!-- Content -->
<textarea type="text" name="content" placeholder="Content" cols="52" rows="7" ></textarea>
</div>
<div class="post-button"><input type="submit" value="Post"></div>
</form>
</div>
</div>
</body>
</html>
73 changes: 73 additions & 0 deletions db_connect.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php
class db_connect {
public $conn;
public $servername;
public $username;
public $password;
public $dbname;

function __construct($_servername, $_username, $_password, $_dbname) {
$this->servername = $_servername;
$this->username = $_username;
$this->password = $_password;
$this->dbname = $_dbname;
}

public function connect() {
$this->conn = new mysqli($this->servername, $this->username, $this->password, $this->dbname);
// Check connection
if ($this->conn->connect_error) {
die("Connection failed: " . $this->conn->connect_error);
}
}

public function close_connection() {
$this->conn->close();
}

public function postQuestion ($name, $email, $questionTopic,$content) {
// require connect()
$sql="INSERT INTO table_name (column1, column2, column3)
VALUES ($name, $email, $questionTopic,$content)";
if ($this->conn->query($sql) === TRUE) {
echo "Record deleted successfully";
}
else {
echo "Error deleting record: " . $this->conn->error;
}
}

public function editQuestion($name, $email, $questionTopic,$content) {
// require connect()
$sql = "UPDATE /*table name*/ SET content=$content WHERE id=/*something*/";
if ($this->conn->query($sql) === TRUE) {
echo "Record deleted successfully";
}
else {
echo "Error deleting record: " . $this->conn->error;
}
}

public function delete() {
// require connect()
$sql="DELETE FROM stackexchange WHERE /*questionId*/";

if ($this->conn->query($sql) === TRUE) {
echo "Record deleted successfully";
}
else {
echo "Error deleting record: " . $this->conn->error;
}
}

public function getTimestamp($table_name, $id) {
$sql = "SELECT time FROM '$table_name' WHERE id='$id'";
return $result = $conn->query($sql);
}

public function getQuestionId ($table_name, $username, $questionTopic) {
$sql = "SELECT time FROM '$table_name' WHERE username='$username' AND questiontopic = '$questionTopic";
return $result = $conn->query($sql);
}
};
?>
32 changes: 32 additions & 0 deletions home.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html>
<head>
<Title> Simple StackExchange </Title>
<link rel="stylesheet" href="styles.css" type="text/css">
<meta> </meta>
</head>
<body>
<div class="container">
<div class="header">
<h1> Simple Stack Exchange </h1>
</div>
<div>
<form>
<input type="text" name="search" placeholder="Search" size = "50" require>
<input type="submit" value="Search">
</form>
</div>
<div>
<p>Cannot find what you are looking for? <a href="question.php">Ask Here</a></p>
</div>
<div class='recent'>
<h2>Recently Asked Question</h2>
<? php
//PHP here
//Create the div through php

?>
</div>
</div>
</body>
</html>
75 changes: 75 additions & 0 deletions question.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<!DOCTYPE html>
<html>
<head>
<Title> Simple StackExchange </Title>
<link rel="stylesheet" href="styles.css" type="text/css">
<script>
//Validate the Form
function validateForm() {
// Alert if the name is empty
var result=true;
var name = document.forms["questionForm"]["name"].value;
if (name == null || name == "") {
alert ("Name must be filled out");
result=false;
}

//alert if the email is empty or is not correct
var email = document.forms["questionForm"]["email"].value;
if (email==null || email=="") {
alert ("Email must be filled out");
result=false;
}
else if (!(/[\w][\@]+[a-z]+[\.]+[\w]/.test(email))) {
alert ("Email must be filled out correctly");
result=false;
}

//Alert if the question topic is empty
var topic = document.forms["questionForm"]["questiontopic"].value;
if (topic == null || topic == "") {
alert ("Question Topic must be filled out");
result=false;
}

//Alert if the content of question is empty
var content = document.forms["questionForm"]["content"].value;
if (content == null || content == "") {
alert ("Content must be filled out");
result=false;
}
return result;
}
</script>
<meta> </meta>
</head>
<body>
<div class="container">
<div class="header">
<h1> Simple Stack Exchange </h1>
</div>
<div class="question">
<div class="heading"><h3> What's your question? </h3></div>
<form action="answer.php" name="questionForm" method="post" onsubmit="return validateForm()">
<div class="textbox">
<!-- Name -->
<input type="text" name="name" placeholder="Name" size="50">
</div>
<div class="textbox">
<!-- Email -->
<input type="text" name="email" placeholder="E-mail" size="50">
</div>
<div class="textbox">
<!-- Question Topic -->
<input type="text" name="questiontopic" placeholder="Question Topic" size="50">
</div>
<div class="textbox">
<!-- Content -->
<textarea type="text" name="content" placeholder="Content" cols="52" rows="7" ></textarea>
</div>
<div class="post-button"><input type="submit" value="Post"></div>
</form>
</div>
</div>
</body>
</html>
33 changes: 33 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.container {
margin-left: auto;
margin-right: auto;
width: 800px;
text-align: center;
padding: 0px;
}

.question {
width : 600px;
margin-left: auto;
margin-right: auto;
}

.heading {
border-bottom: 5px;
border-color: black;
text-align: center;
}

.textbox {
padding-top : 5px;
padding-bottom :5px;
text-align: center;
}

.post-button {
text-align: center;
}

.recent {
text-align: left;
}