Skip to content

Instantly share code, notes, and snippets.

@ncovercash

ncovercash/snippet.php

Last active Sep 24, 2017
Embed
What would you like to do?
<?php
case "ADDSKU":
$skus = $dbh->query("SELECT * FROM `".DB_SKU_NAME_TABLE."`;")->fetchAll();
$skuAssocArray = [];
foreach ($skus as $sku) {
$skuAssocArray[$sku["SKU"]] = $sku["NAME"];
}
echo "Please input the name of the product or CANCEL to go back\n";
echo ">>> ";
$name = trim(readline());
if ($name == "CANCEL") {
break;
}
echo "\n";
echo "Please input the SKU of the product or CANCEL to go back\n";
echo ">>> ";
$sku = trim(readline());
if ($sku == "CANCEL") {
break;
}
if (isset($skuAssocArray[$sku])) {
echo "This SKU is already in the system as ".$skuAssocArray[$sku].".\n";
echo "Returning to main menu\n";
break;
}
$insertStmt = $dbh->prepare("INSERT INTO `".DB_SKU_NAME_TABLE."`(`SKU`, `NAME`) VALUES (:SKU,:NAME);");
$insertStmt->bindParam(":SKU",$sku);
$insertStmt->bindParam(":NAME",$name);
$insertStmt->execute();
echo "Added ".$name."\n";
break;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment