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

13513001 - Pratama Nugraha Damanik #67

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Edit and Post Question
tamadamanik committed Oct 15, 2015
commit 77c6db1aec015143c09716d4cc3c654ecde8ac28
57 changes: 57 additions & 0 deletions askhere.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html lang="en">
<head>
<meta charset="UTF-8">
<?php $id=$_GET['id']; ?>

<?php if ($id==0) $title="Ask New Question";
else $title="Edit Question";
?>

<title><?php echo $title ?></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
<script type="text/javascript" src="js/jvs.js"></script>
</head>
<body>

<?php require("php/database.php"); ?>
<?php
if ($id==0){
$q['username']=''; $q['title']='';
$q['email']=''; $q['content']='';
$t = "new";
}
else {
$q = getQuestion($id);
$t="edit";
}

?>
<div id="Title">
<h1 class="t" href="home.php">Simple StackExchange</h1>
</div>

<div class="raq">What's Your Question ?</div>
<div class="separator"></div>

<form action="home.php" method="POST" onsubmit="return formValidator(this);">
<input id="fname" type="text" name="username" placeholder="Name : " value="<?php echo $q['username'] ?>"/>
<input id="femail" type="text" name="email" placeholder="Email : " value="<?php echo $q['email'] ?>"/>
<input id="ftitle" type="text" name="title" placeholder="Title : " value="<?php echo $q['title'] ?>"/>
<textarea id="fcontent" name="content" placeholder="Content : " ><?php echo $q['content'] ?></textarea>
<div id="ermsg"></div><div id="ermsg2"></div>
<input id="fsubmit" type="submit" value="Post this !"><br>
<input type="hidden" name="aa" value="<?php echo $t ?>" >
<input type="hidden" name="id_q" value="<?php echo $id ?>" >
</form>




</body>
</html>
52 changes: 49 additions & 3 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -72,6 +72,8 @@ p {
a {
color : orange;
text-decoration: none;
font-style: italic;
font-weight: normal;
}
a:hover {
color :red;
@@ -117,7 +119,7 @@ a:hover {
}
.vote {
margin-left:14.5%;
margin-right: 10px;
margin-top: 15px;
// border : 1px solid red;
width :5%;
text-align: center;
@@ -174,17 +176,61 @@ a1 {
color:lawngreen;
}

bb {
.bb {
color : blue;
font-style: normal;
}
bb:hover {
.bb:hover {
color:orange;
cursor:pointer;

}
cc {
color:red;
}
cc:hover {
color:orange;
cursor: pointer;
}

#fname,#ftitle,#femail,#fcontent {

margin-left: 15%;
margin-top:10px;
width:50%;
border : 1px solid black;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
heigth:25px;
font-family: "Trebuchet MS", Helvetica, sans-serif;
font-size: 100%;
border-radius: 4px;
}

#fname {
margin-top: 40px;
}

#ermsg,#ermsg2 {
color:red ;
margin-left:19%;
margin-top: 15px;
font-size: 80%;
}

#fsubmit {
margin-top: 25px;
width:8%;
margin-left:36%;
background-color: white;
border: 2px solid darkgreen ;
color:darkgreen;
font-weight: bold;
height:35px;
border-radius:4px;
}

#fsubmit:hover {
background-color:darkgreen;
color:white;

}
9 changes: 6 additions & 3 deletions db/stackexc.sql
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@
-- http://www.phpmyadmin.net
--
-- Host: 127.0.0.1
-- Generation Time: Oct 10, 2015 at 08:47 AM
-- Generation Time: Oct 10, 2015 at 08:20 PM
-- Server version: 5.6.21
-- PHP Version: 5.6.3

@@ -65,9 +65,12 @@ CREATE TABLE IF NOT EXISTS `question` (
--

INSERT INTO `question` (`id_q`, `title`, `content`, `vote`, `date`, `username`, `email`) VALUES
(1, 'First Question', 'Stack Exchange ????? Testt', 0, '2015-10-07 18:20:01', 'tamadamanik', 'tama.damanik@gmail.com'),
(1, 'First Question', 'TESQ 11', 0, '2015-10-07 18:20:01', 'tamanugraha', 'tama.damanik@yahoo.co.id'),
(2, 'Second Question', 'test', 1, '2015-10-07 23:08:58', 'tatama', 'tamadamanik@yahoo.co.id'),
(3, 'Another Question', ' more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char', 2, '2015-10-10 13:47:19', 'tatamadamanik', 'tatamadamanik@gmail.com');
(3, 'Another Question', ' more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char more than 100 char', 2, '2015-10-10 13:47:19', 'tatamadamanik', 'tatamadamanik@gmail.com'),
(4, 'Try from ask here', 'Try from ask here Try from ask here Try from ask here Try from ask here Try from ask here Try from ask here Try from ask here Try from ask here Try from ask here Try from ask here Try from ask here Try from ask here Try from ask here', 0, '2015-10-10 23:27:31', 'Tama', 'tama.damanik@yahoo.co.id'),
(5, 'Second try', 'Second try Second try Second try Second try ', 0, '2015-10-11 01:03:43', 'tama_n', 'tamadamanik@yahoo.co.id'),
(6, 'Third retry', 'Third', 0, '2015-10-11 01:19:25', 'tata', 'tata@yahoo.com');

--
-- Indexes for dumped tables
23 changes: 17 additions & 6 deletions home.php
Original file line number Diff line number Diff line change
@@ -14,16 +14,27 @@
<body>

<?php require("php/database.php"); ?>
<?php $questions = getAllQuestion(); ?>

<?php $questions = getAllQuestion();
//echo count($questions);
?>
<?php
if (isset($_POST['aa'])&&isset($_POST['id_q'])) {
if ($_POST['aa'] == 'new') echo "new";
else echo"edit";
echo $_POST['id_q'];

//addNewQuestion($_POST);
}

?>
<div id="Title">
<h1 class="t" href="home.php">Simple StackExchange</h1>
</div>
<form id="searchbox" action="">
<input id="search" type="text" placeholder=" Type any keyword here . . . ">
<input id="submit" type="submit" value="Search">
</form>
<p>Cannot find what you are looking for ? <a href="">Ask here</a></p>
<p>Cannot find what you are looking for ? <a href="askhere.php?id=0" >Ask here</a></p>
<div class="raq">Recently Asked Questions</div>
<div class="separator"></div>

@@ -40,7 +51,7 @@
</div>

<div class="thread">
<div class="title"><?php echo $q['title']?></div>
<div class="title" href=""><?php echo $q['title']?></div>
<div class = "content">
<?php echo substr($q['content'],0,150) ?>
<?php if (strlen($q['content'])>150) echo ". . . . . . " ;?>
@@ -52,8 +63,8 @@
<div class="utility">
<aa>asked by : </aa>
<a1><?php echo $q['username']?> </a1>|
<bb>edit </bb>|
<cc>delete</cc>
<a href="askhere.php?id=<?php echo $q['id_q'] ?>" ><span class="bb">edit</span></a> |
<cc href="">delete</cc>
</div>
<div class="uline"></div>

39 changes: 39 additions & 0 deletions js/jvs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
function validateField(form) {
var name = document.getElementById("fname").value;
var title = document.getElementById("ftitle").value;
var content = document.getElementById("fcontent").value;
if (name=== '' || title==='' || content=== '' ) {
if (name==='') form.username.style.border = "2px solid red";
else form.username.style.border = "2px solid blue";
if (title==='') form.title.style.border = "2px solid red";
else form.title.style.border = "2px solid blue";
if (content==='') form.content.style.border = "2px solid red";
else form.content.style.border = "2px solid blue";
document.getElementById("ermsg2").innerHTML = "There is still empty field";
return false;
}
else {
form.username.style.border = "2px solid blue";
form.title.style.border = "2px solid blue";
form.content.style.border = "2px solid blue";
document.getElementById("ermsg2").innerHTML = "";
return true;
}
}

function validateEmail(form) {
var email = document.getElementById("femail").value;
var at="@"; var dot=".";var lstr=email.length;
var lat=email.indexOf(at);var ldot=email.indexOf(dot);
if (lat<1||lat===lstr||ldot<1||ldot===lstr||ldot-lat<2){
document.getElementById("ermsg").innerHTML = "* Make sure that your email is valid";
form.email.style.border = "2px solid red";
return false;}
else {document.getElementById("ermsg").innerHTML = "";form.email.style.border = "2px solid blue";return true;}

}
function formValidator(form) {
var a =validateEmail(form),b=validateField(form);
if (!a||!b) return false ;
else return false;
}
23 changes: 23 additions & 0 deletions php/database.php
Original file line number Diff line number Diff line change
@@ -38,3 +38,26 @@ function countAnswer($id) {
return $ret;
}

function getQuestion($id) {
global $conn;


$sql = "SELECT * FROM question WHERE id_q=$id";

$result = mysqli_query($conn, $sql);
$ret = mysqli_fetch_array($result,MYSQLI_ASSOC);

return $ret;
}

function addNewQuestion($q) {
global $conn;
$sql1 = "SELECT MAX(id_q) as max FROM question" ;
$result1 = mysqli_query($conn,$sql1);
$ret1 = mysqli_fetch_array($result1,MYSQLI_ASSOC)['max'];
$nid = $ret1 + 1;
$sql2 = "INSERT INTO question (id_q,username,email,title,content,date,vote) VALUES ('$nid','$q[username]','$q[email]','$q[title]','$q[content]', CURRENT_TIMESTAMP,0)";
$result2 = mysqli_query($conn,$sql2);
return $result2;

}