<?php session_start(); include '../assets/constant/config.php'; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } ?> <?php include('include/sidebar.php'); ?> <?php include('include/header.php'); ?> <div class="page-content-wrapper "> <div class="container-fluid"> <div class="row"> <div class="col-sm-12"> <div class="page-title-box"> <div class="btn-group float-right"> </div> <h4 class="page-title">Edit Project</h4> </div> </div> <div class="clearfix"></div> </div> <!-- end page title end breadcrumb --> <div class="row"> <div class="col-lg-12"> <div class="card"> <div class="card-body"> <div class="tab-content"> <div class="tab-pane active p-3" id="home" role="tabpanel"> <form name="myform" action="app/product_crud.php" class="row" method="POST" enctype="multipart/form-data" onsubmit="return validation()" id="add_service"> <?php $stmt1 = $conn->prepare("SELECT * FROM `productlist` WHERE id=? AND delete_status= 0 "); $stmt1->execute([$_POST['id']]); $record1 = $stmt1->fetchAll(); foreach ($record1 as $key1) { ?> <input type="hidden" name="id" value="<?php echo $key1['id'];?>"> <!-- <div class="form-group col-md-6"> <label class="control-label">Category<span class="text-danger">*</span></label> <select class="form-control select2" name="category_id" > <//?php $stmt = $conn->prepare("SELECT * FROM `category` where delete_status= '0' "); $stmt->execute(); $record = $stmt->fetchAll(); foreach ($record as $key) { ?> <option value="</?php echo $key['id'];?>" </?php if($key['id']==$key1['category_id']){ echo 'selected';}?>></?php echo $key['heading']; ?></option> </?php } ?> </select> </div> --> <div class="form-group col-md-6"> <label class="control-label">Name<span class="text-danger">*</span></label> <input class="form-control" type="text" name="pro_name" value="<?php echo $key1['pro_name'];?>" required="" /> </div> <div class="form-group col-md-6"> <label class="control-label">Short Content<span class="text-danger">*</span></label> <input class="form-control" type="text" name="short_content" value="<?php echo $key1['short_content'];?>" /> </div> <div class="form-group col-md-6"> <label class="control-label">Existing Photo</label><br> <?php // Read the image file and encode it to Base64 $imagePath = "../assets/images/" . $key1['photo']; // Path to your image file $imageData = file_get_contents($imagePath); $base64Image = base64_encode($imageData); ?> <input type="hidden" value="<?php echo $key1['photo'] ?>" name="old_photo_img"> <img class="img-fluid" src="data:image/jpeg;base64,<?php echo $base64Image; ?>" style="width:100px;height:auto;"><br> </div> <div class="form-group col-md-6"> <label class="control-label">Change Photo</label> <input class="form-control" type="file" name="photo"> </div> <div class="form-group col-md-6"> <label class="control-label"> Content<span class="text-danger">*</span></label> <textarea class="form-control" id="ckeditor1" type="text" name="content" value=""><?php echo $key1['content'];?></textarea> </div> <div class="form-group col-md-12"> <button class="btn btn-primary" type="submit" name="update" onclick="addService()">Submit</button> </div> <?php } ?> </form> </div> </div> </div> </div><!--end card--> </div><!--end col--> </div><!--end row--> </div> <!-- Page content Wrapper --> </div> <!-- content --> <?php include('include/footer.php'); ?> <script type="text/javascript"> function addService() { jQuery.validator.addMethod("alphanumeric", function(value, element) { return this.optional(element) || /^(?=.*[a-zA-Z])[a-zA-Z0-9\s!@#$%^&*()_-]+$/.test(value); }, "Please enter alphabet characters only"); jQuery.validator.addMethod("lettersonly", function(value, element) { // Check if the value is empty if (value.trim() === "") { return false; } return /^[a-zA-Z\s]*$/.test(value); }, "Please enter alphabet characters only"); $('#add_service').validate({ rules: { category_id: { required: true, }, pro_name: { required: true }, content: { required: true } }, messages: { category_id: { required: "Select category ", pattern: "Only alphanumeric characters and spaces are allowed" }, pro_name: { required: "Please enter a pro_name ", pattern: "Only alphanumeric characters and spaces are allowed" }, content: { required: "Please enter a content", pattern: "Only alphanumeric characters and spaces are allowed" } } }); }; </script> <!-- <script> function validation() { var fileInput = document.getElementById('add_service').photo; var filePath = fileInput.value; var allowedExtensions = /(\.jpg|\.jpeg|\.png)$/i; if (!allowedExtensions.exec(filePath)) { alert('Invalid file type! Please upload a JPG, JPEG, or PNG image.'); fileInput.value = ''; return false; } return true; } </script> --> <script type="text/javascript"> $(".add-more").on('click',function(){ var html = $(".copy").html(); $(".after-add-more").before(html); $(".after-add-more").next().find('select[name^="product_id"]').select2(); show_no(); }); $("body").on("click",".remove",function(){ $(this).parents(".control-group").remove(); show_no(); }); function show_no() { var row_cnt=0; $( ".sr_no" ).each(function() { row_cnt++; $( this ).html(row_cnt); }); } </script>