D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
home
/
buildteksolution
/
public_html
/
superadmin
/
Filename :
add-product.php
back
Copy
<?php include 'cn.php'; session_start(); if(isset($_SESSION['username'])) { if(isset($_POST['submit'])) { // print_r($_POST); // die(); date_default_timezone_set('Asia/Kolkata'); $curdate= date('d-m-Y H:i'); if( $_FILES['img']['name']==''){ $imageName=$row1['image']; } else { $image =$_FILES['img']['tmp_name']; $imageName =$_FILES['img']['name']; $imageSize =$_FILES['img']['size']; $imageType =$_FILES['img']['type']; $target_dir = "products/"; $target_file = $target_dir . basename($_FILES["img"]["name"]); $uploadOk = 1; $imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION)); move_uploaded_file($_FILES["img"]["tmp_name"],$target_dir.$imageName); } /* echo $imageName; echo $_POST['name']; echo $_POST['price']; echo $_POST['category']; echo $_POST['description']; echo $_POST['pid'];die;*/ $dec= $_POST['editor']; $sql = "INSERT INTO `products`(`name`, `url`, `url1`,`image`, `description`) VALUES ('".$_POST['name']."','".$_POST['url']."','".$_POST['url1']."','$imageName','$dec') "; $result = $con->query($sql); if($result){ $slect = "SELECT * FROM products WHERE name ='".$_POST['name']."'&&image='$imageName'"; $qury = mysqli_query($con,$slect); $pdata = mysqli_fetch_assoc($qury); $prdtid = $pdata['id']; $cimage=$_POST['hdnvarimage']; $cname=$_POST['hdnvarName']; $question = $_POST['hdnfaqName']; $answer = $_POST['hdnfaqans']; foreach($question as $key=>$faqvalue){ $faq="INSERT INTO `faq`(`question`, `answer`, `pid`) VALUES ('$question[$key]','$answer[$key]','$prdtid')"; $faqry = mysqli_query($con,$faq); } foreach ($cname as $key => $value) { $procusts = "INSERT INTO `childproducts`(`image`, `product`, `pid`) VALUES ('$cimage[$key]','$cname[$key]','$prdtid')"; // print_r($procusts); $pquery = mysqli_query($con,$procusts); } // die(); echo "<script type='text/javascript'>alert(\"Add Successfully\") location.href='products.php'; </script>";} else { echo "<script type='text/javascript'>alert(\"not added\") location.href='products.php'; </script>";} } ?> <!DOCTYPE html> <html lang="en"> <head> <!-- Required meta tags --> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" /> <link rel="stylesheet" href="https://cdn.datatables.net/1.11.3/css/dataTables.bootstrap4.min.css" crossorigin="anonymous"> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.5.2/css/bootstrap.css" crossorigin="anonymous"> <title>SMV</title> <link href="../logo-2.png" rel="shortcut icon" type="image/png"> <style> .scrollbar { overflow: auto; white-space: nowrap; } </style> </head> <body> <div class="container-scroller"> <?php include 'header.php'; ?> <!-- partial --> <div class="main-panel"> <div class="content-wrapper pb-0"> <div class="col-12 grid-margin stretch-card"> <div class="card"> <div class="card-body"> <h4 class="card-title">Add Product</h4> <!-- <p class="card-description">Basic form elements</p> --> <form class="forms-sample" method="post" enctype="multipart/form-data"> <div class="form-group"> <label for="exampleInputName1">Product Name</label> <input type="text" class="form-control" name="name" placeholder="Name" required/> </div> <div class="form-group"> <label for="exampleInputName1">Amazon Url</label> <input type="text" class="form-control" name="url" placeholder="Enter Url" required/> </div> <div class="form-group"> <label for="exampleInputName1">Opencart Url</label> <input type="text" class="form-control" name="url1" placeholder="Enter Url" required/> </div> <div class="form-group"> <label for="exampleInputName1">Product Image</label> <input type="file" name="img" class="form-control" required> </div> <div class="form-group"> <label for="exampleInputName1">Description</label> <textarea name="editor" id="editor" required></textarea> </div> <input type='hidden' name='hdnSno' id='hdnSno' value='1' /> <input type='hidden' name='hdnfq' id='hdnSfq' value='1' /> <div class='variableContent'> </div> <br> <br> <table class="table table-striped table-bordered" style="width:100%"> <thead> <tr style="background: #f26110;color: #fff;"> <th>Sno</th> <th>Name</th> <th>Image</th> <th>Action</th> </tr> </thead> <tbody id='varTbody'> </tbody> </table> <br> <br> <a class='btn btn-primary' onclick='return addVar()'>Add Variant</a> <a class='btn btn-primary' id="varsub" onclick='return submitVar()'>Submit Variant</a> <br> <br> <div class='variableFaq'> </div> <table class="table table-striped table-bordered" style="width:100%"> <thead> <tr style="background: #f26110;color: #fff;"> <th>Qustion</th> <th>Answer</th> <th>Action</th> </tr> </thead> <tbody id='varfaq'> </tbody> </table> <br> <br> <a class='btn btn-primary' onclick='return addFaq()'>Add Faq</a> <a class='btn btn-primary' onclick='return submitFaq()'>Faq Submit</a> <br><br> <button type="submit" class="btn btn-primary me-2" name="submit"> Submit </button> </form> </div> </div> </div> <script src="ckeditor/ckeditor.js"></script> <script> CKEDITOR.replace('editor'); </script> </div> <!-- content-wrapper ends --> <!-- partial:partials/_footer.html --> <?php include'footer.php'; ?> <!-- partial --> </div> <!-- main-panel ends --> </div> <!-- page-body-wrapper ends --> </div> <!-- container-scroller --> <script src="https://code.jquery.com/jquery-3.5.1.js"></script> <script src="https://cdn.datatables.net/1.11.3/js/jquery.dataTables.min.js"></script> <script src="https://cdn.datatables.net/1.11.3/js/dataTables.bootstrap4.min.js"></script> <script> $(document).ready(function() { $('#example').DataTable(); }); </script> <script> function addVar() { // alert(); let varContent = `<div class='col-md-12'> <div class="form-group"> <label for="exampleInputName1">Variable Title</label> <input type="text" class="form-control" id='varName' name="varName[]" placeholder="Name" /> </div> <div class="form-group"> <label for="exampleInputName1">Variable Image</label> <input type="file" class="form-control" id="varimg" name="varImg" placeholder="varImg" /> </div> </div>`; $(".variableContent").html(varContent); } function addFaq() { // alert(); let varFaq = `<div class='col-md-12'> <div class="form-group"> <label for="exampleInputName1">Faq Question</label> <input type="text" class="form-control" id='varQues' name="varQues[]" placeholder="Faq Question" /> </div> <div class="form-group"> <label for="exampleInputName1">Faq Answer</label> <input type="text" class="form-control" id="varAns" name="varAns" placeholder="Faq Answer" /> </div> </div>`; $(".variableFaq").html(varFaq); } function submitFaq(){ var faqName = $("#varQues").val(); var faqAns = $("#varAns").val(); if(faqName=="" && faqAns==""){ return false } var rowID = $("#hdnSno").val(); // var varName = $("#varName").val(); // var sno = rowID+1; // alert(rowID); $("#varfaq").append(`<tr id='faqdel[`+rowID+`]'> <td><input type='hidden' id='hdnfaqName[`+rowID+`]' name='hdnfaqName[`+rowID+`]' value='`+faqName+`' required />`+faqName+`</td> <td><input type='hidden' id='hdnfaqans[`+rowID+`]' name='hdnfaqans[`+rowID+`]' value='`+faqAns+`' />`+faqAns+`</td> <td><a class='btn btn-sm btn-danger' onclick="delFaq(`+rowID+`)">delete</a></td> </tr>`) rowID++; $("#hdnSno").val(rowID); $("#varQues"). val(''); $("#varAns"). val(''); } function submitVar(){ var name = $("#varName").val(); // alert(name); if(name == ""){ return false } // alert(name); // alert($("#varTbody tr").length()); // if($("#varTbody tr").length() > 1){ // } // async function submitVar() { var fd = new FormData(); // alert(fd); var files = $('#varimg')[0].files[0]; fd.append('file', files); var image =""; $.ajax({ url: 'upload.php', type: 'post', async:false, data: fd, contentType: false, processData: false, success: function(response){ image += response; // alert(image); // $('#showimage').html(image); }, }); // alert('The file has been uploaded successfully.'); // alert(image); var rowID = $("#hdnSno").val(); var varName = $("#varName").val(); // var sno = rowID+1; // alert(rowID); $("#varTbody").append(`<tr id='vardel[`+rowID+`]'> <td>`+ rowID +`</td> <td><input type='hidden' id='hdnvarName[`+rowID+`]' name='hdnvarName[`+rowID+`]' value='`+varName+`' required/>`+varName+`</td> <td> <input type='hidden' name='hdnvarimage[`+rowID+`]' value='`+image+`' required /> <img src=`+image+` height="50" width="50"></td> <td><a class='btn btn-sm btn-danger' onclick="delVar(`+rowID+`)">delete</a></td> </tr>`) rowID++; $("#hdnSno").val(rowID); $("#varName"). val(''); // $("#varName"). val(''); } function delVar(varid) { $('#vardel\\['+varid+'\\]').remove(); } function delFaq(faqid) { $('#faqdel\\['+faqid+'\\]').remove(); } </script> </body> </html> <?php } else { header("location:login.php"); } ?>