Skip to content

Instantly share code, notes, and snippets.

@ncovercash
Last active September 24, 2017 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ncovercash/470ade64982aaadbd10cb9f475c5523e to your computer and use it in GitHub Desktop.
Save ncovercash/470ade64982aaadbd10cb9f475c5523e to your computer and use it in GitHub Desktop.
<?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