format('M. j, Y'); if (isset($_GET['categoryId'])){ $dsn = 'mysql:host=localhost;dbname=my_guitar_shop1'; $username ='root'; $password =''; try { $db = new PDO($dsn, $username, $password); } catch (PDOException $e) { $message = $e->getMessage(); $message .= 'For the followings reason' . $message . '$my_guitar_shop2 database couldnt be opened, thanks!'; echo $message; exit(); } //Get data from the form $category_id = $_GET['categoryId']; $code =$_GET['code']; $name = $_GET['name']; $price = $_GET['price']; //Insert product //Validate inputs if(empty($code)||empty($name)||empty($price)){ echo 'Invalid Data'; } else { $query ="INSERT INTO products (categoryID, productCode, productName, listPrice) VALUES ('$category_id', '$code', '$name', '$price')"; $insert_count = $db->exec($query); $message = '

' . 'Insert count: ' . $insert_count . '

'; } //Get all product $query = "SELECT * FROM PRODUCTS ORDER BY productID"; $products = $db->query($query); } if(isset($_GET['product_id'])) { $dsn = 'mysql:host=localhost;dbname=my_guitar_shop1'; $username ='root'; $password =''; try { $db = new PDO($dsn, $username, $password); } catch (PDOException $e) { $message = $e->getMessage(); $message .= 'For the followings reason' . $message . '$my_guitar_shop2 database couldnt be opened, thanks!'; echo $message; exit(); } $product_Id = $_GET['product_id']; $query = "DELETE FROM products WHERE productID ='$product_Id'"; $delete_count = $db->exec($query); $message = '

' . 'Delete count: ' . $delete_count . '

'; } ?> My Portfolio

ADDING PRODUCT TO DATABASE

List of Products

Product Name Listed Price
Delete