35 lines
774 B
PHP
Executable File
35 lines
774 B
PHP
Executable File
<?php
|
|
|
|
// this is the script that actually submits the post into the db
|
|
|
|
session_start();
|
|
include('config.php');
|
|
|
|
// Create connection
|
|
$conn = new mysqli($servername, $username, $password, $dbname);
|
|
// Check connection
|
|
if ($conn->connect_error) {
|
|
die("Connection failed: " . $conn->connect_error);
|
|
}
|
|
|
|
if ($_POST['url'] == "") {
|
|
die('Empty');
|
|
}
|
|
if ($_POST['title'] == "") {
|
|
die('Empty');
|
|
}
|
|
if ($_SESSION['name'] == "") {
|
|
die('You are not logged in!');
|
|
}
|
|
$sql = "INSERT INTO posts (url, title, poster)
|
|
VALUES ('". $_POST['url']. "', '". $_POST['title'] ."', '".htmlspecialchars($_SESSION['name'], ENT_QUOTES)."')";
|
|
|
|
if ($conn->query($sql) === TRUE) {
|
|
header('Location: index.php');
|
|
} else {
|
|
echo "Error: " . $sql . "<br>" . $conn->error;
|
|
}
|
|
|
|
$conn->close();
|
|
|
|
?>
|