%PDF- %PDF-
Direktori : /proc/thread-self/root/proc/self/root/home/medipszd/www/admin/ |
Current File : //proc/thread-self/root/proc/self/root/home/medipszd/www/admin/category_add.php |
<?php include 'includes/session.php'; if(isset($_POST['add'])){ $name = $_POST['name']; $conn = $pdo->open(); $stmt = $conn->prepare("SELECT *, COUNT(*) AS numrows FROM category WHERE name=:name"); $stmt->execute(['name'=>$name]); $row = $stmt->fetch(); if($row['numrows'] > 0){ $_SESSION['error'] = 'Category already exist'; } else{ try{ $stmt = $conn->prepare("INSERT INTO category (name) VALUES (:name)"); $stmt->execute(['name'=>$name]); $_SESSION['success'] = 'Category added successfully'; } catch(PDOException $e){ $_SESSION['error'] = $e->getMessage(); } } $pdo->close(); } else{ $_SESSION['error'] = 'Fill up category form first'; } header('location: category.php'); ?>