I'am sorry if this question is stupid , but how I can save canvas image to database via php I've searched a lot but did not found anything working and useful
and here is the code that I use it just popup print form
<script>
function print(){
var canvas1 = document.getElementById("testCanvas");
var ctx1 = canvas1.getContext("2d");
var img = canvas1.toDataURL("image/png");
img = encodeURIComponent(img);
$.ajax({
url: 'upload.php',
data: { data: img },
type: 'post',
success: function(data) {
console.log(data);
alert("Done");
}
});
</script>
<button onclick="print()">Click me</button><br>
Upload.php
<?php
$data = $_POST['data'];
$server = "localhost";
$username = "root";
$password = "";
$database = "sports";
$bd = mysql_connect($server, $username, $password) or die("1");
$ok = mysql_select_db($database, $bd) or die("2");
$sql = "INSERT INTO image (myimage) VALUES ($data)";
if( ! mysql_query($sql) )
{
echo "Error: " . mysql_error();
}
echo $qry;
?>