Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // start the session
- if (!isset($_SESSION['loggedstaff']))
- {
- session_start();
- }
- // the required files
- require_once "../database/dbconn.php";
- require_once "../includes/functions.php";
- $condb = connect();
- $Product_code= $_POST['Product_code'];
- $Product_name= $_POST['Product_name'];
- $Product_descroption= $_POST['Product_descroption'];
- $Product_size= $_POST['Product_size'];
- $Product_price= $_POST['Product_price'];
- //set initial value of error message
- $error_message = "";
- //validate data
- $error_message .= validate_product_code($Product_code);
- if ($error_message != "")
- include_once "changeproduct.php";
- else
- {
- //store data in session variables
- $sProduct_code = sanitiseMySQL($Product_code);
- $sProduct_name = sanitiseMySQL($Product_name);
- $sProduct_descroption = sanitiseMySQL($Product_descroption);
- $sProduct_size = sanitiseMySQL($Product_size);
- $sProduct_price = sanitiseMySQL($Product_price);
- // start the image code here
- if ($_FILES['filetoupload']["error"] > 0)
- {
- $error_message = mysqli_error($condb);
- include_once"changeproduct.php";
- }
- else if (($_FILES["filetoupload"]['type'] == "image/gif") || ($_FILES["filetoupload"]['type'] == "image/jpeg") || ($_FILES["filetoupload"]['type'] == "image/png") )
- {
- move_uploaded_file($_FILES['filetoupload']['tmp_name'],IMAGEFOLDER.$_FILES['filetoupload']['name']);
- echo "file uploaded";
- $error_message = mysqli_error($condb);
- //validate data
- $error_message .= validate_product_code($Product_code);
- if ($error_message != "")
- include_once "changeproduct.php";
- else
- if (!isset($_POST['changeitem'])){
- $oQuery = mysqli_query($condb, "SELECT * FROM tblproducts WHERE Product_code = '$Product_code'");
- $oAssoc = mysqli_fetch_assoc($oQuery);
- // run through form fields and check if they are blank
- if ($_POST['Product_code'] == ""){
- $_POST['Product_code'] = $oAssoc['Product_code'];
- };
- if ($_POST['Product_name'] == ""){
- $_POST['Product_name'] = $oAssoc['Product_name'];
- };
- if ($_POST['Product_descroption'] == ""){
- $_POST['Product_descroption'] = $oAssoc['Product_descroption'];
- };
- if ($_POST['Product_size'] == ""){
- $_POST['Product_size'] = $oAssoc['Product_size'];
- };
- if ($_POST['Product_price'] == ""){
- $_POST['Product_price'] = $oAssoc['Product_price'];
- };
- //here is image
- if ($_FILES['filetoupload']['name']== ""){
- $_FILES['filetoupload']['name'] = $oAssoc{$_FILES['filetoupload']['tmp_name']};
- };
- // 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
- $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']."'
- WHERE Product_code = '".$_POST['Product_code']."'");
- };
- $result = mysqli_query($condb, $mysqli_query);
- if ($result)
- {
- echo "product insert worked";
- }
- else
- {
- die (mysqli_error($condb));
- }
- header("Location: ../shop/catalogue.php");
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment