我想在点击图片时更新数据库值,此图片也必须更改。它只适用于超级' superata'设置为0,因此变为1,在另一种情况下,仅更改图像,但不更改db值(' superata'是tinyint(1))。为什么呢?
<?php
$risultato= mysql_query("select * from sfide where id='$id' ");
$ris=mysql_fetch_array($risultato);
if($ris[superata]==0) {?>
<img id="myImage" onclick="changeImage()" src="icons/switch_off.png">
<?} else {?>
<img id="myImage" onclick="changeImage()" src="icons/switch_on.png">
<?}?>
<script>
function changeImage() {
var image = document.getElementById('myImage');
if (image.src.match("icons/switch_on")) {
image.src = "icons/switch_off.png";
<? mysql_query("UPDATE sfide SET superata='0' WHERE id='$id' ");?>
} else {
image.src = "icons/switch_on.png";
<? mysql_query("UPDATE sfide SET superata='1' WHERE id='$id' ");?>
}
}