forked from jasonhillinger/Mini-Stackoverflow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathposts.php
62 lines (46 loc) · 1.79 KB
/
posts.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
<?php
include_once 'server.php';
//session_start();
$errors = array();
//mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
//title, questionText, asker, views, voteCount, bestAnswer
if($_SERVER["REQUEST_METHOD"] == "POST"){
$user = $_SESSION["userID"];
if(isset($_POST['submitQuestion'])){ //if this is true then its a question post
$title = mysqli_real_escape_string($db, $_POST['title']);
$questionText = mysqli_real_escape_string($db, $_POST['userQuestion']);
//do sql query for question
if(count($errors) == 0){
$query = "INSERT INTO questions (title, questionText, asker) VALUES ('$title','$questionText','$user')"; //This is where the SQL querie will go (Insert statement) Table strucure: title, questionText, asker, views, voteCount, bestAnswer
mysqli_query($db,$query);
//echo("Question posted successfully");
echo("<meta http-equiv=\"refresh\" content=\"0\" />");
}
else{
while(count($errors) != 0){
echo(array_pop($errors));
}
echo("Question posting failed!");
echo("<meta http-equiv=\"refresh\" content=\"5\" />");
}
}
else if(isset($_POST['submitAnswer'])){
$refQuestion = mysqli_real_escape_string($db, $_POST['refQuestion']);
$answerText = mysqli_real_escape_string($db, $_POST['userAnswer']);
if(count($errors) == 0){
//do answer sql querie
$query = "INSERT INTO answers (refQuestion, answerText, answerer) VALUES ('$refQuestion','$answerText','$user')"; //This is where the SQL query will go
mysqli_query($db,$query);
//echo("Answer posted successfully");
echo("<meta http-equiv=\"refresh\" content=\"0\" />");
}
else{
while(count($errors) != 0){
echo(array_pop($errors));
}
echo("Answer posting failed!");
echo("<meta http-equiv=\"refresh\" content=\"5; url=index.php\" />");
}
}
}
?>