You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.7 KiB
PHP

<?php
// Initialize the session
session_start();
// Check if the user is already logged in, if yes then redirect him to welcome page
if(isset($_SESSION["loggedinAdmin"]) && $_SESSION["loggedinAdmin"] === true){
echo "";
}else header("location: ../index.php");
// Include config file
require_once("../model/db.php");
$title = $_POST["title"];
$body = $_POST["body"];
if(!is_null($title)){
$conn = $pdo;
try {
$sql = "INSERT INTO article ( title, body ) values ( '$title', '$body' );";
$conn->exec($sql);
} catch (PDOException $e) {
echo "Error in $from: Not Found";
}
}
header("location: ../insertWhat.php");
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Insert Article</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<style>
body{ font: 14px sans-serif; }
.wrapper{ width: 360px; padding: 20px; }
</style>
</head>
<body>
<div class="wrapper">
<h2>Insert Article</h2>
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
<div class="form-group">
<label>Title</label>
<input type="text" name="title" class="form-control">
</div>
<div class="form-group">
<label>Body</label>
<textarea rows="4" cols="50" name="body" class="form-control"></textarea>
</div>
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
<a class="btn btn-link ml-2" href="insertWhat.php">Cancel</a>
</div>
</form>
</div>
</body>
</html>