将数字标志保存为png到数据库中

时间:2018-03-19 18:09:56

标签: javascript php mysql ajax

我正在尝试使用mysql和php将数字符号从php保存到我的数据库中 它可以工作,但它不会保存任何东西。 我在头部添加了js库

javascript,HTML code

<canvas class="sign-pad" id="sign-pad" width="300" height="100"></canvas>
<button id="btnSaveSign">Save Signature</button>
     <script>

$(document).ready(function(e){

    $(document).ready(function() {
        $('#signArea').signaturePad({drawOnly:true, drawBezierCurves:true, lineTop:90});
    });

    $("#btnSaveSign").click(function(e){
        html2canvas([document.getElementById('sign-pad')], {
            onrendered: function (canvas) {
                var canvas_img_data = canvas.toDataURL('image/png');
                var img_data = canvas_img_data.replace(/^data:image\/(png|jpg);base64,/, "");

                //ajax call to save image inside folder
                $.ajax({
                    url: 'save_sign.php?su=$id',
                    data: { img_data:img_data },
                    type: 'post',
                    dataType: 'json',
                    success: function (response) {
                       window.location.reload();
                    }
                });
            }
        });
    });

});
</script>

save_sign.php代码

    <?php 
if (isset($_post['su'])){
        $su_id= $_post['su'];
        }
        $imagedata = base64_decode($_POST['img_data']);


           require 'includes/connection.php';
$query =mysqli_query($database, "UPDATE `user registration` SET `sign`='$imagedata' WHERE `SupplierID`=$su_id"); 


?>

0 个答案:

没有答案