Advertisement
Guest User

Untitled

a guest
Jun 25th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1.  
  2. function addcategory() {
  3. $serverWIBLname = getConn("servername");
  4. $userWOBLname = getConn("username");
  5. $passBABLword = getConn("password");
  6.  
  7. $categoryrecord = json_decode(file_get_contents('php://input')); //get user from
  8.  
  9. $categoryid = $categoryrecord->CategoryID;
  10. $category = $categoryrecord->Category;
  11. $categorydescription = $categoryrecord->Description;
  12. $categorydisplay = $categoryrecord->Display;
  13. $categoryoffers = $categoryrecord->Offers;
  14. $categoryordering = $categoryrecord->Ordering;
  15.  
  16. // Connect
  17. $mysqli = new mysqli($serverWIBLname, $userWOBLname, $passBABLword, $userWOBLname);
  18.  
  19. if(!$mysqli) die('Could not connect: ' . mysql_error());
  20. // Prepare parameters
  21. $mysqli->query("set names 'utf8'");
  22. $mysqli->query("SET @categoryid = " . "'" . $mysqli->real_escape_string($categoryid) . "'");
  23. $mysqli->query("SET @category = " . "'" . $mysqli->real_escape_string($category) . "'");
  24. $mysqli->query("SET @categorydescription = " . "'" . $mysqli->real_escape_string($categorydescription) . "'");
  25. $mysqli->query("SET @categorydisplay = " . "'" . $mysqli->real_escape_string($categorydisplay) . "'");
  26. $mysqli->query("SET @categoryoffers = " . "'" . $mysqli->real_escape_string($categoryoffers) . "'");
  27. $mysqli->query("SET @categoryordering = " . "'" . $mysqli->real_escape_string($categoryordering) . "'");
  28.  
  29. // IF(500<1000, "YES", "NO")
  30.  
  31. // Call sproc
  32. if ($categoryid > 0) {
  33. // edit
  34. if ($category <> "") {
  35. $result = $mysqli->query(" UPDATE Categories"
  36. ." SET Category = @category,"
  37. ." Description = @categorydescription,"
  38. ." Offers = @categoryoffers,"
  39. ." Ordering = @categoryordering,"
  40. ." Display = @categorydisplay"
  41. ." WHERE CategoryID = @categoryid");
  42. if(!$result) die("Fail: (" . $mysqli->errno . ") " . $mysqli->error);
  43. };
  44. } else {
  45. // add
  46. if ($category <> "") {
  47. $result = $mysqli->query( " INSERT INTO Categories"
  48. ." (Category, Description, Offers, Ordering, Display)"
  49. ." VALUES (@category, @categorydescription, IFNULL(@categoryoffers,0), IFNULL(@categoryordering,0), IFNULL(@categorydisplay,0))");
  50. if(!$result) die("Fail: (" . $mysqli->errno . ") " . $mysqli->error);
  51. };
  52. };
  53.  
  54. //echo "saved";
  55.  
  56. $mysqli->close();
  57. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement