prepare('SELECT * FROM books WHERE sn =:uid'); $stmt_edit->execute(array(':uid'=>$id)); $edit_row = $stmt_edit->fetch(PDO::FETCH_ASSOC); extract($edit_row); } else { header("Location: home.php"); } if(isset($_POST['btn_save_updates'])) { //$username = $_POST['user_name'];// user name //$userjob = $_POST['user_job'];// user email $title = $_POST['title']; $authur = $_POST['authur']; $price = $_POST['price']; $intro = $_POST['intro']; //$ddst = $_POST['ddescrp']; $cat = $_POST['cat']; $imgFile = $_FILES['user_image']['name']; $tmp_dir = $_FILES['user_image']['tmp_name']; $imgSize = $_FILES['user_image']['size']; if($imgFile) { $upload_dir = '../img/'; // upload directory $imgExt = strtolower(pathinfo($imgFile,PATHINFO_EXTENSION)); // get image extension $valid_extensions = array('jpeg', 'jpg', 'png', 'gif'); // valid extensions $userpic = rand(1000,1000000).".".$imgExt; if(in_array($imgExt, $valid_extensions)) { if($imgSize < 5000000) { unlink($upload_dir.$edit_row['image']); move_uploaded_file($tmp_dir,$upload_dir.$userpic); } else { $errMSG = "Sorry, your file is too large it should be less then 5MB"; } } else { $errMSG = "Sorry, only JPG, JPEG, PNG & GIF files are allowed."; } } else { // if no image selected the old image remain as it is. $userpic = $edit_row['image']; // old image from database } // if no error occured, continue ....(item_code,item_name,brand_name,model_number, weight, dimension, description,category,quantity,price,image) VALUES(:itc, :itn,:bn,:mn,:wt,:dm,:ds,:ct,:qu,:pr,:im)'); if(!isset($errMSG)) { $stmt = $DB_con->prepare('UPDATE books SET category = :ct, title =:a , authur =:b, intro =:c, price=:d, image =:im WHERE sn=:uid'); //$stmt->bindParam(':uname',$username); $stmt->bindParam(':ct',$cat); $stmt->bindParam(':a',$title); $stmt->bindParam(':b',$authur); $stmt->bindParam(':c',$intro); $stmt->bindParam(':d',$price); $stmt->bindParam(':im',$userpic); $stmt->bindParam(':uid',$id); if($stmt->execute()) { ?> Edit Products Records
 

cancel