ausghostdog

Untitled

Jun 2nd, 2012
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. <?php
  2. // start the session
  3. if (!isset($_SESSION['loggedstaff']))
  4. {
  5. session_start();
  6. }
  7.  
  8. // the required files
  9. require_once "../database/dbconn.php";
  10. require_once "../includes/functions.php";
  11. $condb = connect();
  12. $Product_code= $_POST['Product_code'];
  13. $Product_name= $_POST['Product_name'];
  14. $Product_descroption= $_POST['Product_descroption'];
  15. $Product_size= $_POST['Product_size'];
  16. $Product_price= $_POST['Product_price'];
  17.  
  18. //set initial value of error message
  19. $error_message = "";
  20.  
  21. //validate data
  22. $error_message .= validate_product_code($Product_code);
  23.  
  24.  
  25.  
  26. if ($error_message != "")
  27. include_once "changeproduct.php";
  28. else
  29. {
  30. //store data in session variables
  31. $sProduct_code = sanitiseMySQL($Product_code);
  32. $sProduct_name = sanitiseMySQL($Product_name);
  33. $sProduct_descroption = sanitiseMySQL($Product_descroption);
  34. $sProduct_size = sanitiseMySQL($Product_size);
  35. $sProduct_price = sanitiseMySQL($Product_price);
  36.  
  37. // start the image code here
  38. if ($_FILES['filetoupload']["error"] > 0)
  39. {
  40. $error_message = mysqli_error($condb);
  41. include_once"changeproduct.php";
  42. }
  43.  
  44.  
  45. else if (($_FILES["filetoupload"]['type'] == "image/gif") || ($_FILES["filetoupload"]['type'] == "image/jpeg") || ($_FILES["filetoupload"]['type'] == "image/png") )
  46. {
  47. move_uploaded_file($_FILES['filetoupload']['tmp_name'],IMAGEFOLDER.$_FILES['filetoupload']['name']);
  48. echo "file uploaded";
  49. $error_message = mysqli_error($condb);
  50. //validate data
  51. $error_message .= validate_product_code($Product_code);
  52.  
  53. if ($error_message != "")
  54. include_once "changeproduct.php";
  55. else
  56.  
  57.  
  58.  
  59. if (!isset($_POST['changeitem'])){
  60. $oQuery = mysqli_query($condb, "SELECT * FROM tblproducts WHERE Product_code = '$Product_code'");
  61. $oAssoc = mysqli_fetch_assoc($oQuery);
  62.  
  63. // run through form fields and check if they are blank
  64. if ($_POST['Product_code'] == ""){
  65. $_POST['Product_code'] = $oAssoc['Product_code'];
  66. };
  67.  
  68. if ($_POST['Product_name'] == ""){
  69. $_POST['Product_name'] = $oAssoc['Product_name'];
  70. };
  71.  
  72. if ($_POST['Product_descroption'] == ""){
  73. $_POST['Product_descroption'] = $oAssoc['Product_descroption'];
  74. };
  75.  
  76. if ($_POST['Product_size'] == ""){
  77. $_POST['Product_size'] = $oAssoc['Product_size'];
  78. };
  79.  
  80. if ($_POST['Product_price'] == ""){
  81. $_POST['Product_price'] = $oAssoc['Product_price'];
  82. };
  83. //here is image
  84. if ($_FILES['filetoupload']['name']== ""){
  85. $_FILES['filetoupload']['name'] = $oAssoc{$_FILES['filetoupload']['tmp_name']};
  86. };
  87. // if cahnges are made from the first value that are made here. only item that must be compleated is the product code, everything else can be left blank and it will not change it, if an item is changed it will only change that and leave the rest as they were
  88. $mysqli_query= ("UPDATE tblproducts SET Product_name = '".$_POST['Product_name']."', Product_descroption = '".$_POST['Product_descroption']."',Product_size = '".$_POST['Product_size']."',Product_price = '".$_POST['Product_price']."', product_image = '".$_FILES['filetoupload']['name']."'
  89. WHERE Product_code = '".$_POST['Product_code']."'");
  90. };
  91.  
  92. $result = mysqli_query($condb, $mysqli_query);
  93.  
  94. if ($result)
  95. {
  96. echo "product insert worked";
  97. }
  98. else
  99. {
  100. die (mysqli_error($condb));
  101. }
  102. header("Location: ../shop/catalogue.php");
  103.  
  104. }
  105.  
  106. }
  107.  
  108. ?>
Advertisement
Add Comment
Please, Sign In to add comment