I need to put a mysql_query in the onClick event of a div. I tried this, but it does not work.
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++;
}
the script in the head of main page is
<script type="text/javascript">
function doSomething(){
$.post("del_notif.php");
return false;
}
</script>
and the del_notif.php
include 'files/config.php';
mysql_query("UPDATE notifiche SET a='delete' WHERE id='$_POST[del_noti]'");
mysql_*functions anymore, they are deprecated. See Why shouldn't I use mysql_* functions in PHP? for details. Instead you should learn about prepared statements and use either PDO or MySQLi. If you can't decide which, this article will help you. If you pick PDO, here is a good tutorial.I tried this, but not work..what does not work? Any error messages? Calleddel_notif.phpplain (not via ajax)? Please escape variables with user content in it. An yes: never ever usemysql_*as mentioned by @MarcelKorpelmysql_*... but doesn't matter as long as he usesmysql_*it's unsafe anyway.