javascript - post data-id using ajax form -


i've question ajax form. so, can see following ajax code have data-id . i'm getting id in .pmsc div. when press #upmsc uploading image not getting error, getting result chrome developer console, no upload, no inserting image name in database. i'm doing wrong here.

enter image description here

then ajax submit form this

$('body').on('change', '#upmsc', function(e) {    e.preventdefault();    var id = $(".pmsc").attr("data-id");    var data = 'id=' + id;    $("#musicform").ajaxform({       type: "post",       data: data,       cache: false,       target: '.appended',       beforesubmit: function() {          //       },       success: function(response) {          //          $(".showecho").html(response);       },       error: function() {}    }).submit(); }); 

my html form this:

    <form id="cfrm" class="options-form" method="post" enctype="multipart/form-data" action="'.$base_url.'upload.php">        <label class="mcup" for="upcmsc"></label> <input type="file" name="musiccover" id="upcmsc" />     </form>     <div class="pmsc" id="56">     </div> 

and php code this

<?php include_once 'inc/inc.php'; $valid_formats = array("jpg", "png", "gif", "bmp","jpeg","png","jpg","jpeg","gif","bmp"); if(isset($_post) , $_server['request_method'] == "post" && isset($_post['id'])) {     $id = mysqli_real_escape_string($db, $_post['id']);     $name = $_files['musiccover']['name'];     $size = $_files['musiccover']['size'];     if(strlen($name)) {         $ext = getextension($name);         if(in_array($ext,$valid_formats)) {             if($size<(50024*50024)) {                  $actual_image_name = time().$uid.".".$ext;                 $tmp = $_files['musiccover']['tmp_name'];                 if(move_uploaded_file($tmp, $mcoverpath.$actual_image_name)) {                     $data=$huhu->music_cover_image_upload($id,$actual_image_name);                     if($data){                         echo '<img class="cover covermsc" src="'.$base_url.$mcoverpath.$actual_image_name.'">';                         }                   } else {                       echo "fail upload folder read access.";                 }                 } else                   echo "image file size max 1 mb";                          } else           echo "invalid file format.";      } else          echo "please select image..!";         exit;  }   ?> 

var data = 'id=' + id; $("#musicform").ajaxform({   type: "post",   data: data, 

you set additional data string while should object. fails checks in php code. try this:

var data = {id: id}; 

found more problems php code braces, try this:

<?php include_once 'inc/inc.php'; $valid_formats = array("jpg", "png", "gif", "bmp","jpeg","png","jpg","jpeg","gif","bmp"); if(isset($_post) , $_server['request_method'] == "post" && isset($_post['id'])) {     $id = mysqli_real_escape_string($db, $_post['id']);     $name = $_files['musiccover']['name'];     $size = $_files['musiccover']['size'];      if(strlen($name)) {         $ext = getextension($name);         if(in_array($ext,$valid_formats)) {             if($size<(50024*50024)) {                  $actual_image_name = time().$uid.".".$ext;                 $tmp = $_files['musiccover']['tmp_name'];                  if(move_uploaded_file($tmp, $mcoverpath.$actual_image_name)) {                     $data=$huhu->music_cover_image_upload($id,$actual_image_name);                     if($newdata){                         echo '<img class="cover covermsc" src="'.$base_url.$mcoverpath.$actual_image_name.'">';                     }                 } else {                     echo "fail upload folder read access.";                 }             } else {                 echo "image file size max 1 mb";                     }         } else {             echo "invalid file format.";         }     } else {         echo "please select image..!";         exit;     } } else {     echo '1';    } ?> 

Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -