Advertisement
Guest User

Untitled

a guest
Feb 25th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1. $data = file_get_contents("php://input");
  2. $objData = json_decode($data);
  3.  
  4. $table = $objData -> table;
  5. $brand = $objData -> brand;
  6. $numsCost = $objData -> cost;
  7. $customerPrice = $objData -> price;
  8. $inStock = $objData -> inStock;
  9. $notes = $objData -> notes;
  10. $unID = $objData -> uniqueID;
  11. $amtPerBox = $objData -> amountPerBox;
  12. $size = $objData -> size;
  13.  
  14. $dbh = new PDO("mysql:host=HOST;dbname=NAME","USER","PASS");
  15.  
  16. if(strcmp($table,"cups")==0){ //"cups" table is one of the odd tables with an extra column, this will work
  17.     $sql = "INSERT INTO $table SET uniqueID = '$unID', brand = '$brand', cost = '$numsCost', price = '$customerPrice', inStock = '$inStock', size = '$size', notes = '$notes'";
  18. }elseif(strcmp($table,"cleaners")==0){ //"cleaners" is the other one, this will work
  19.     $sql = "INSERT INTO $table SET uniqueID = '$unID', brand = '$brand', cost = '$numsCost', price = '$customerPrice', inStock = '$inStock', amtPerBox = '$amtPerBox', notes = '$notes'";
  20. }else{ //everything else falls into this category, this will not work
  21.     $sql = "INSERT INTO :table SET uniqueID = '$unID', brand = :brand, cost = :cost, price = :price, inStock = :stockQuantity, notes = :notes";
  22.    
  23. }
  24. $stmt = $dbh->prepare($sql);
  25. $stmt->bindParam(':table', $table);
  26. $stmt->bindParam(':brand',$brand);
  27. $stmt->bindParam(':amtPerBox',$amtPerBox);
  28. $stmt->bindParam(':size', $size);
  29. $stmt->bindParam(':cost', $numsCost);
  30. $stmt->bindParam(':price', $customerPrice);
  31. $stmt->bindParam(':stockQuantity', $inStock);
  32. $stmt->bindParam(':uniqueID', $unID);
  33. $stmt->bindParam(':notes', $notes);
  34. $stmt->execute();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement