forked from if-itb/IF3110-2015-T1
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AddAnswer.php
28 lines (25 loc) · 830 Bytes
/
AddAnswer.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
<?php
$servername = "localhost";
$username = "root";
$password = "dininta";
$dbname = "stackexchange";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Add to database
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$email = $_POST["email"];
$content = $_POST["content"];
$questionID = $_POST["questionID"];
$sql = "INSERT INTO answer (name, email, content, questionID) VALUES ('$name', '$email', '$content', '$questionID')";
$conn->query($sql);
$sql = "UPDATE question SET answers=answers+1 WHERE questionID='$questionID'";
$conn->query($sql);
}
header("Location: /stackExchange/ShowQuestion.php?id=".$questionID);
exit;
?>