<?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