No Description

insertCategory.php 625B

12345678910111213141516
  1. <?php
  2. require_once 'config.php';
  3. require_once 'dbh.inc.php';
  4. require_once 'checkLogin.php';
  5. // IF USER ENTERS PAGE AFTER 'Save' BUTTON HAS BEEN PRESSED (FROM categories.php), INSERT CATEGORY TO DATABASE
  6. // ELSE (IF USER ENTERED THIS PAGE WITHOUT SUBMITING A FORM) REDIRECT TO categories.php
  7. if(isset($_POST['insertCategory'])) {
  8. $categoria = mysqli_real_escape_string($connection, $_POST['categoria']);
  9. $query = "INSERT INTO `category` (categoria) VALUES ('".$categoria."');";
  10. if(!mysqli_query($connection, $query)) die("Error: ".mysqli_error($connection));
  11. }
  12. header('Location: ../categories.php');
  13. exit();