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.
87 lines
2.9 KiB
PHP
87 lines
2.9 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");
|
|
require_once("listLatest.php");
|
|
|
|
$name = $_POST["name"];
|
|
$alc = $_POST["alc"];
|
|
$ibu = $_POST["ibu"];
|
|
$description = $_POST["description"];
|
|
$brewery_id = $_POST["brewery_id"];
|
|
$degree = $_POST["degree"];
|
|
|
|
$arrayOfBreweries = listBeersByBreweryNAN( $pdo );
|
|
|
|
if(!is_null($name)){
|
|
$conn = $pdo;
|
|
try {
|
|
$sql = "INSERT INTO beer ( name, alc, ibu, description, brewery_id, degree ) values ( '$name', $alc, '$ibu', '$description', '$brewery_id', '$degree' );";
|
|
echo $sql;
|
|
$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 Beer</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 Beer</h2>
|
|
<form action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]); ?>" method="post">
|
|
<div class="form-group">
|
|
<label>Beer Name</label>
|
|
<input type="text" name="name" class="form-control">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Alc (float for example: 4.2)</label>
|
|
<input type="text" name="alc" class="form-control">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>IBU</label>
|
|
<input type="text" name="ibu" class="form-control">
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Description</label>
|
|
<textarea rows="4" cols="50" name="description" class="form-control"></textarea>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Parent Brewery</label>
|
|
<select name="brewery_id" class="form-control">
|
|
<?php foreach($arrayOfBreweries as $row) : ?>
|
|
<option value="<?= $row['id'] ?>"><?= $row['name'] ?></option>
|
|
<?php endforeach ?>
|
|
</select>
|
|
</div>
|
|
<div class="form-group">
|
|
<label>Degree</label>
|
|
<input type="text" name="degree" class="form-control">
|
|
</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>
|