I am trying to update seen(a bool in the database) if the seen button is clicked and delete a row if the delete button is clicked. But it doesn't seem to work nor do I get any data(mysql_error) back. But the last else part works and I get the data.
This is the php code :
if(isset($_POST["seen"])){
$fid=$_POST["id"];
$sql="UPDATE feedback SET seen=1 WHERE ID=$fid";
mysql_query($sql,$con);
echo mysql_error($con);
} else if(isset($_POST["delete"])){
$fid=$_POST["id"];
$sql="DELETE from feedback WHERE ID=$fid";
mysql_query($sql,$con);
echo mysql_error($con);
} else{
$sql="SELECT * FROM feedback";
$result=mysql_query($sql,$con);
while($row=mysql_fetch_array($result)){
$jsonData[]=$row;
}
echo json_encode($jsonData);
}
and js code:
$("#seen").click(function(){
$.post("main_php.php",{},function(data){
alert(data);
});
});
$("#delete").click(function(){
var fid = $('#ID').val();
$.post("main_php.php",{id:fid},function(data){
console.log(data);
})
});
Please tell me what may be wrong with it!!!!
seen and delete are the names of buttons btw
mysql_interface functions. It's 2016 already. Use PDO or mysqli. And prepared statements with bind placeholders are not that hard. Really. And I'm so going to pass in the value'1 OR 1=1 --'forid.