D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
realadss
/
.trash
/
admin
/
Filename :
product_edit.php
back
Copy
<?php include('include/header.php'); $id=$_GET['eid']; $sql=mysqli_query($conn,"select * from product where id='$id'"); $fetch=mysqli_fetch_array($sql); if(isset($_POST['update'])) { $category =$_POST['addcategory']; $title =$_POST['title']; $price = $_POST['price']; $desc =$_POST['desc']; $imgtitle =$_POST['imgtitle']; $imgalt =$_POST['imgalt']; $rimg1_alt =$_POST['rimg1alt']; $rimg2_alt =$_POST['rimg2alt']; $rimg3_alt =$_POST['rimg3alt']; $meta_title = $_POST['metatitle']; $meta_desc = $_POST['metadesc']; $meta_key = $_POST['metakey']; $seosyntax = $_POST['syntax']; $rimage1_title =$_POST['rimage1_title']; $rimage2_title =$_POST['rimage2_title']; $rimage3_title =$_POST['rimage3_title']; $uniqe_image1 = $fetch['image']; $image01 = $_FILES['image']['name']; if(!empty($image01)){ $unique = uniqid()." ".$image01; $image1 = "images/product/".$unique; $stmp_name1 = $_FILES['image']['tmp_name']; move_uploaded_file($stmp_name1, $image1); }else{ $image1=$uniqe_image1; } $uniqe_image2 = $fetch['rimage1']; $image02 = $_FILES['rimage1']['name']; if(!empty($image02)){ $unique2 = uniqid()." ".$image02; $image2 = "images/product/".$unique2; $stmp_name2 = $_FILES['rimage1']['tmp_name']; move_uploaded_file($stmp_name2, $image2); }else{ $image2=$uniqe_image2; } $uniqe_image3 = $fetch['rimage2']; $image03 = $_FILES['rimage2']['name']; if(!empty($image03)){ $unique3 = uniqid()." ".$image03; $image3 = "images/product/".$unique3; $stmp_name3 = $_FILES['rimage2']['tmp_name']; move_uploaded_file($stmp_name3, $image3); }else{ $image3=$uniqe_image3; } $uniqe_image4 = $fetch['rimage3']; $image04 = $_FILES['rimage3']['name']; if(!empty($image04)){ $unique4 = uniqid()." ".$image04; $image4 = "images/product/".$unique4; $stmp_name4 = $_FILES['rimage3']['tmp_name']; move_uploaded_file($stmp_name4, $image4); }else{ $image4=$uniqe_image4; } $text = strtolower($title); $desc = $_POST['desc']; $replaceArray1 = array( '"' => """, "'" => "'", ); $modifiedText1 = str_replace(array_keys($replaceArray1), array_values($replaceArray1), $desc); // $pixcel = $_POST['syntax']; // $escaped_html_line = $conn->real_escape_string($pixcel); $slug = $_POST['slug']; $replaceArray2 = array( ' ' => "-", ); $modifiedText2 = str_replace(array_keys($replaceArray2), array_values($replaceArray2), $slug); $data= mysqli_query($conn,"UPDATE `product` SET `id`='$id',`meta_title`='$meta_title',`meta_desc`='$meta_desc',`meta_key`='$meta_key',`Category`='$category',`title`='$text',`description`='$modifiedText1',`price`='$price',`image`='$image1',`imgtitle`='$imgtitle',`imgalt`='$imgalt',`rimage1`='$image2',`rimage2`='$image3',`rimage3`='$image4',rimage1_alt='$rimg1_alt',rimage2_alt='$rimg2_alt',rimage3_alt='$rimg3_alt',slug='$modifiedText2',seo_syntax='$seosyntax',rimage1_title='$rimage1_title',rimage2_title='$rimage2_title',rimage3_title='$rimage3_title' WHERE id='$id'"); if($data) { $id = $_GET['eid']; $ques = $_POST['question'] ?? []; // Assuming this array contains the questions $anss = $_POST['answer'] ?? []; // Assuming this array contains the answers // $faq_id = $_POST['faq_id']; // delete old faq $del = "DELETE FROM `product_faq` WHERE product_id ='$id'"; $query = mysqli_query($conn,$del); if(isset($ques) && is_array($ques) && count($ques) > 0) { foreach($ques as $key_id => $val) { $ques_val = $val; $ans_val = $anss[$key_id] ?? ""; mysqli_query($conn, "INSERT INTO product_faq ( question, answer, product_id) VALUES ('$ques_val', '$ans_val', '$id') "); } } // for ($i = 0; $i < sizeof($ques); $i++) { // $faqId = $faq_id[$i]; // $newQuestion = $ques[$i]; // $newAnswer = $anss[$i]; // // Perform an insert or update query based on the existence of the FAQ ID // mysqli_query($conn, "INSERT INTO product_faq (id, question, answer, product_id) VALUES ('$faqId', '$newQuestion', '$newAnswer', '$id') ON DUPLICATE KEY UPDATE question='$newQuestion', answer='$newAnswer'"); echo "<script>alert('Data Updated');window.location.href='products.php';</script>"; // } } else { echo mysqli_error($conn); } } ?> <!-- Content Wrapper. Contains page content --> <div class="content-wrapper"> <div class="container-full"> <!-- Main content --> <section class="content"> <div class="box"> <div class="box-header with-border"> <h4 class="box-title">Edit Product</h4> </div> <!-- /.box-header --> <div class="box-body"> <form role="form" method="POST" enctype="multipart/form-data"> <!-- text input --> <div class="form-group"> <label class="form-label">Meta Title</label> <input type="text" class="form-control" value="<?php echo $fetch['meta_title'];?>" name="metatitle" required> </div> <div class="form-group"> <label class="form-label">Meta Description</label> <input type="text" class="form-control" value="<?php echo $fetch['meta_desc'];?>" name="metadesc" required maxlength="180"> </div> <div class="form-group"> <label class="form-label">Meta Keywords</label> <input type="text" class="form-control" value="<?php echo $fetch['meta_key'];?>" name="metakey" required> </div> <div class="form-group"> <label class="form-label">Slug</label> <input type="text" class="form-control" value="<?php echo $fetch['slug'];?>" name="slug" required> </div> <div class="form-group"> <label class="form-label">SEO Syntax</label> <textarea class="form-control" name="syntax"><?php echo $fetch['seo_syntax'];?></textarea> </div> <div class="row"> <div class="col-6"> <div class="form-group"> <label class="form-label">Category</label> <select class="form-control" name="addcategory" required> <?php $catdata = mysqli_query($conn,"select * from decore_category"); while ($row = mysqli_fetch_assoc($catdata)) { ?> <option <?php echo $fetch['Category'] == $row['id'] ? "selected" : ""; ?> value="<?php echo $row['id']; ?>" ><?php echo $row['categoryName']; ?></option> <?php }?> </select> </div> </div> <div class="col-6"> <div class="form-group"> <label class="form-label">price</label> <input type="text" class="form-control" value="<?php echo $fetch['price'];?>" name="price" > </div> </div> <div class="col-6"> <div class="form-group"> <label class="form-label">Product Name/Title</label> <input type="text" class="form-control" value="<?php echo $fetch['title'];?>" name="title" required> </div> </div> <div class="col-6"> <div class="form-group"> <label class="form-label">Image</label> <input type="file" class="form-control" accept="image/png, image/jpeg, image/jpg" name="image" onchange="ShowImage(event)" > <img src='<?php echo $fetch['image'];?>' value="" width="200" id="image" /> </div> </div> <div class="col-6"> <div class="form-group"> <label class="form-label">Image Title</label> <input type="text" class="form-control" value="<?php echo $fetch['imgtitle'];?>" placeholder="Enter ..." name="imgtitle" required> </div> </div> <div class="col-6"> <div class="form-group"> <label class="form-label">Image Alt</label> <input type="text" class="form-control" placeholder="Enter ..." value="<?php echo $fetch['imgalt'];?>" name="imgalt" required> </div> </div> <div class="col-4"> <div class="form-group"> <label class="form-label">Related Image1 (optional)</label> <input type="file" class="form-control" accept="image/png, image/jpeg, image/jpg" name="rimage1" onchange="ShowImage2(event)" > <img src="<?php echo $fetch['rimage1'];?>" width="200" height="100" id="image2" /> </div> </div> <div class="col-4"> <div class="form-group"> <label class="form-label">Related Image1 Alt</label> <input type="text" class="form-control" placeholder="Enter ..." value="<?php echo $fetch['rimage1_alt'];?>" name="rimg1alt" required> </div> </div> <div class="col-4"> <div class="form-group"> <label class="form-label">Related Image1 Title</label> <input type="text" class="form-control" placeholder="Enter ..." value="<?php echo $fetch['rimage1_title'];?>" name="rimage1_title" required> </div> </div> <div class="col-4"> <div class="form-group"> <label class="form-label">Related Image2 (optional)</label> <input type="file" class="form-control" accept="image/png, image/jpeg, image/jpg" name="rimage2" onchange="ShowImage3(event)" > <img src="<?php echo $fetch['rimage2'];?>" width="200" height="100" id="image3" /> </div> </div> <div class="col-4"> <div class="form-group"> <label class="form-label">Related Image2 Alt</label> <input type="text" class="form-control" placeholder="Enter ..." value="<?php echo $fetch['rimage2_alt'];?>" name="rimg2alt" required> </div> </div> <div class="col-4"> <div class="form-group"> <label class="form-label">Related Image2 Title</label> <input type="text" class="form-control" placeholder="Enter ..." value="<?php echo $fetch['rimage2_title'];?>" name="rimage2_title" required> </div> </div> <div class="col-4"> <div class="form-group"> <label class="form-label">Related Image3 (optional)</label> <input type="file" class="form-control" accept="image/png, image/jpeg, image/jpg" name="rimage3" onchange="ShowImage4(event)" > <img src="<?php echo $fetch['rimage3'];?>" width="200" height="100" id="image4" /> </div> </div> <div class="col-4"> <div class="form-group"> <label class="form-label">Related Image3 Alt</label> <input type="text" class="form-control" placeholder="Enter ..." value="<?php echo $fetch['rimage3_alt'];?>" name="rimg3alt"> </div> </div> <div class="col-4"> <div class="form-group"> <label class="form-label">Related Image3 Title</label> <input type="text" class="form-control" placeholder="Enter ..." value="<?php echo $fetch['rimage3_title'];?>" name="rimage3_title"> </div> </div> <div class="form-group"> <label class="form-label">FAQ</label> <div class="row"> <div class="customer_records"> <?php $id=$_GET['eid']; $sql2=mysqli_query($conn,"select * from product_faq where product_id = '$id'"); while($row_faq = mysqli_fetch_array($sql2)){ ?> <div class="faq-item"> <input type="hidden" name="faq_id[]" value="<?php echo $row_faq['id'] ?? "";?>"> <input name="question[]" type="text" placeholder="Enter Question" value="<?php echo $row_faq['question'];?>" class="form-control" style="width:40% !important;display:inline-block;margin-bottom: 10px;"> <input name="answer[]" type="text" placeholder="Enter Answer" value="<?php echo $row_faq['answer'];?>" class="form-control" style="width:40% !important;display:inline-block;margin-bottom: 10px;"> <a href="#" class="remove-field" data-faq-id="<?php echo $row_faq['id']; ?>">Remove</a> </div> <?php }?> <div id="additionalFields"></div> <button id="addMore">Add More</button> </div> </div> </div> </div> <div class="form-group"> <label class="form-label">Description</label> <textarea name="desc" id="editor"><?php echo $fetch['description'];?></textarea> </div> <div class="box-footer"> <button type="submit" class="btn btn-success" name="update">Update</button> </div> </form> </div> <!-- /.box-body --> </div> </div> <!-- /.box-body --> </div> </section> <!-- /.content --> </div> </div> <link rel="stylesheet" href="https://cdn.ckeditor.com/ckeditor5/42.0.1/ckeditor5.css"> <script type="importmap"> { "imports": { "ckeditor5": "https://cdn.ckeditor.com/ckeditor5/42.0.1/ckeditor5.js", "ckeditor5/": "https://cdn.ckeditor.com/ckeditor5/42.0.1/" } } </script> <script type="module"> import { ClassicEditor, Essentials, Paragraph, Bold, Italic, Font, Alignment, CodeBlock, Code } from 'ckeditor5'; ClassicEditor .create( document.querySelector( '#editor' ), { plugins: [ Essentials, Paragraph, Bold, Italic, Font, CodeBlock, Code, Alignment ], toolbar: [ 'undo', 'redo', '|', 'bold', 'italic', '|', 'fontSize', 'fontFamily', 'fontColor', 'fontBackgroundColor', '|', 'alignment', '|', 'code', 'codeBlock' ] } ) .then( editor => { window.editor = editor; } ) .catch( error => { console.error( error ); } ); </script> <!--<script src="//cdn.ckeditor.com/4.22.1/standard/ckeditor.js"></script>--> <script> CKEDITOR.replace( 'editor'); </script> <script> CKEDITOR.replace( 'editor2'); </script> <?php include('include/footer.php');?>