Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $data = file_get_contents("php://input");
- $objData = json_decode($data);
- $table = $objData -> table;
- $brand = $objData -> brand;
- $numsCost = $objData -> cost;
- $customerPrice = $objData -> price;
- $inStock = $objData -> inStock;
- $notes = $objData -> notes;
- $unID = $objData -> uniqueID;
- $amtPerBox = $objData -> amountPerBox;
- $size = $objData -> size;
- $dbh = new PDO("mysql:host=HOST;dbname=NAME","USER","PASS");
- if(strcmp($table,"cups")==0){ //"cups" table is one of the odd tables with an extra column, this will work
- $sql = "INSERT INTO $table SET uniqueID = '$unID', brand = '$brand', cost = '$numsCost', price = '$customerPrice', inStock = '$inStock', size = '$size', notes = '$notes'";
- }elseif(strcmp($table,"cleaners")==0){ //"cleaners" is the other one, this will work
- $sql = "INSERT INTO $table SET uniqueID = '$unID', brand = '$brand', cost = '$numsCost', price = '$customerPrice', inStock = '$inStock', amtPerBox = '$amtPerBox', notes = '$notes'";
- }else{ //everything else falls into this category, this will not work
- $sql = "INSERT INTO :table SET uniqueID = '$unID', brand = :brand, cost = :cost, price = :price, inStock = :stockQuantity, notes = :notes";
- }
- $stmt = $dbh->prepare($sql);
- $stmt->bindParam(':table', $table);
- $stmt->bindParam(':brand',$brand);
- $stmt->bindParam(':amtPerBox',$amtPerBox);
- $stmt->bindParam(':size', $size);
- $stmt->bindParam(':cost', $numsCost);
- $stmt->bindParam(':price', $customerPrice);
- $stmt->bindParam(':stockQuantity', $inStock);
- $stmt->bindParam(':uniqueID', $unID);
- $stmt->bindParam(':notes', $notes);
- $stmt->execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement