-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatePost.php
More file actions
22 lines (15 loc) · 764 Bytes
/
createPost.php
File metadata and controls
22 lines (15 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
include_once 'dbconfig.php';
if(isset($_POST["title"]) && isset($_POST["comment"])){
$conn = mysqli_connect($dbconfig["host"], $dbconfig["user"], $dbconfig["password"], $dbconfig["name"]) or die("Errore: ".mysqli_connect_error());
$title = mysqli_real_escape_string($conn, $_POST["title"]);
$comment = mysqli_real_escape_string($conn, $_POST["comment"]);
$username = mysqli_real_escape_string($conn, $_POST["username"]);
$publish_date = date("Y-m-d");
$query = "INSERT INTO posts(title, content, username, num_likes, num_comments, publish_date) VALUES('$title', '$comment', '$username', 0, 0, '$publish_date')";
if(mysqli_query($conn, $query)) {
header("Location: profile.php");
}
mysqli_close($conn);
}
?>