gpt4 book ai didi

php - 在 onclick div 上运行 php mysql_query

转载 作者:太空宇宙 更新时间:2023-11-03 12:21:16 24 4
gpt4 key购买 nike

我需要在 divonClick 事件中放置一个 mysql_query。我试过这个,但它不起作用。

notifiche.php

while ($i < $result) {
$id_noti = mysql_result($res, $i, "id");
$msg=mysql_result($res,$i,"msg");
?>
<div class="box" align="left" style="color: #5c5c5c; padding:4px; border-bottom: 1px solid #c0c0c0; width: 170px !important; position:relative;z-index: auto;">
<div onClick="doSomething();" class="close_box" align="right"style="font-weight:bold; position:absolute;right:0; top:0; z-index:1;cursor:pointer;">
x
<input type="hidden" name="del_noti" value="<?echo $id_noti;?>">
</div>
<? echo $msg; ?>
</div>
<? $i++;
}

主页面头部的脚本是

<script type="text/javascript">
function doSomething(){
$.post("del_notif.php");
return false;
}
</script>

和 del_notif.php

include 'files/config.php';
mysql_query("UPDATE notifiche SET a='delete' WHERE id='$_POST[del_noti]'");

最佳答案

您必须将参数传递给您的 doSomething 函数

<div onClick="doSomething(<?echo $id_noti;?>)"...>

在你的脚本中

<script type="text/javascript">
function doSomething(id){
$.post("del_notif.php", {id: id});
return false;
}
</script>

在服务器上

include 'files/config.php';
mysql_query("UPDATE notifiche SET a='delete' WHERE id=". (int) $_POST["id"]);

关于php - 在 onclick div 上运行 php mysql_query,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19906222/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com