dousong2023 2016-02-28 08:28
浏览 35

单击按钮时,需要下载画布并将sql整数增加1

I have been able to get my button to download the file (html canvas), but I need it to also increment a SQL field by one.

I am not sure how much code you will need, so I will begin by giving you the parts I am trying to get to talk to each other.

PHP:

$insert = mysql_query("update UserName set logins = logins+1 where password='$password' AND username='$username'", $connection);

HTML Button:

<div>
<a id="dload" download="YourFileName.png">Download as image</a>
</div>

JAVA (On the same page as button)

function download() {
var dt = c5.toDataURL("image/png", 1.0);
this.href = dt;
};

function insert(){
var insert = <?php $insert; ?>;
};

dload.addEventListener('click', download, false);
dload.addEventListener('click', insert, false);

The PHP code lives on a file called login.php as a variable. Login.php is included on the file that contains the HTML button and Java above.

The download part works. The SQL query is correct and works when run on the database. But I am just not sure how to integrate so it both downloads and adds one to the database.

Thanks for looking.

EDIT:

I can now get it to do both, but now it only increments the SQL field once per logon (will download every time though). The user needs to logout , then log back in for it to work properly again. I need it to increment by one every time they click download.

I changed this:

function download() {
var dt = c5.toDataURL("image/png", 1.0);
this.href = dt;
};

function insert(){
var insert = <?php $insert; ?>;
};

dload.addEventListener('click', download, false);
dload.addEventListener('click', insert, false);

to this (which is what I had originally):

function download() {
var dt = c5.toDataURL("image/png", 1.0);
this.href = dt;
};
dload.addEventListener('click', download, false);

And changed my button to this:

echo <a id="dload" download="YourFileName.png" value="<?php echo $insert; ?>">Download as image</a>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 Vue3 大型图片数据拖动排序
    • ¥15 划分vlan后不通了
    • ¥15 GDI处理通道视频时总是带有白色锯齿
    • ¥20 用雷电模拟器安装百达屋apk一直闪退
    • ¥15 算能科技20240506咨询(拒绝大模型回答)
    • ¥15 自适应 AR 模型 参数估计Matlab程序
    • ¥100 角动量包络面如何用MATLAB绘制
    • ¥15 merge函数占用内存过大
    • ¥15 使用EMD去噪处理RML2016数据集时候的原理
    • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大