Last active
September 24, 2017 18:29
-
-
Save ncovercash/470ade64982aaadbd10cb9f475c5523e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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