Tell me why the database update does not work? Here is the code, when it is executed, for some reason, the data is deleted, and not updated, what could be the problem? Here is the code itself:
<?php include("bd.php"); if ($_POST['id']) { $id = $_POST['id']; $status = $_POST['status']; $id = mysql_escape_String($id); echo "update users set status='$status' where id='$id'"; mysql_query("update users set status='$status' where id='$id'"); } ?>
UPD:
$(function() { $("h4").click(function() { var titleid = $(this).attr("id"); var sid=titleid.split("title"); var id=sid[1]; var dataString = 'id='+ id ; var parent = $(this).parent(); $(this).hide(); $("#formbox"+id).show(); return false; }); $(".save").click(function() { var A=$(this).parent().parent(); var X=A.attr('id'); var d=X.split("formbox"); var id=d[1]; var Z=$("#"+X+" input.content").val(); var dataString = 'id='+ id +'$status='+Z ; $.ajax({ type: "POST", url: "status.php", cache: false, success: function(data) { A.hide(); $("#title"+id).html(Z); $("#title"+id).show(); } }); return false; }); $(".cancel").click(function() { var A=$(this).parent().parent(); var X= A.attr("id"); var d=X.split("formbox"); var id=d[1]; var parent = $(this).parent(); $("#title"+id).show(); A.hide(); return false; }); });
The code manipulates the div, and then ajax updates the data.
id
is numeric, then quotes are not needed. And it is necessary not Muskl_escape_string, and intval () - Oleg Arkhipov(int)$_POST['id']
, string values are more correctly escaped withmysql_real_escape_string()
, and SQL service words are usually written in capital letters:UPDATE users SET status='$status' WHERE id=$id
(numeric variables - without quotes, text variables - in quotes) - and you won’t get confused, and the code will be more readable - Metal Heart