This repository was archived by the owner on Oct 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathprocess.php
More file actions
43 lines (37 loc) · 1.39 KB
/
process.php
File metadata and controls
43 lines (37 loc) · 1.39 KB
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
<?php
include_once("config.php");
// SQL Connect
$sql = mysqli_connect($config["MySQL_host"],$config["MySQL_user"],$config["MySQL_pass"],$config["MySQL_db"]);
if ($config["Debug"] && mysqli_connect_errno()){
die("Failed to connect to MySQL: " . mysqli_connect_error());
}
if (!empty($_POST)) {
// Insert into database
$stmt = $sql->prepare("INSERT INTO stories (title, url_title, author, content, date, hits) VALUES (?, ?, ?, ?, ?, ?)");
$title = $sql->real_escape_string($_POST["title"]);
$title = !empty($title) ? $title : "Untitled";
// Generate SEO URL
$ut_recipe = strlen($title) > 30 ? substr($title, 0, 30) . "-" . date("m-d") : $title . "-" . date("m-d");
$ut_result = $sql->query("SELECT url_title FROM stories WHERE url_title='$ut_recipe'");
if ($ut_result->num_rows > 0) {
$url_title = strlen($title) > 30 ? substr($title, 0, 30) . "-" . date("m-d") . $ut_result->num_rows : $title . "-" . date("m-d") . "-" . $ut_result->num_rows;
} else {
$url_title = $ut_recipe;
}
$author = $sql->real_escape_string($_POST["author"]);
$author = !empty($author) ? $author : "Anonymous";
$content = $_POST["content"];
$date = date("Y-m-d H:i:s");
$hits = 0;
$stmt->bind_param("sssssi", $title, $url_title, $author, $content, $date, $hits);
if ($stmt->execute()) {
echo $url_title;
die();
}
$stmt->close();
} else {
echo "new";
die();
}
mysqli_close($sql);
?>