When i click a button

<input id='delete' type='button' name='delete' value='Delete' onclick='deletePost(<? echo $id;?>);'>

I want it to go to this function which is sent to my delete php code

function deletePost(id){
	$('.content-num' + id).hide('slow');
			$.ajax({
				type: "POST",
				url: "/func/delete.php",
				data: "id="+ id,
				success: function(){
			}});
			alert(id);
	}

Im new to javascript and ajax so i think im doing that wrong but im not sure if i made a stupid mistake on my php

<?
include ("../css/mysql.php");
session_start();
$id = htmlspecialchars(trim($_POST['id']));

$query= mysql_query("SELECT id_user FROM content WHERE id=$id");
$row= mysql_fetch_assoc($query);
$id_user= $row['id_user'];

if ($id_user==$_SESSION['iden'])
{
	$delete=mysql_query("UPDATE content SET delete='1' WHERE id=$id");
}
?>

So, before commenting on any particular code, what exactly is your problem? What happens right now when you click the button?

Get a response from your php code to debug:

function deletePost(id){
	$('.content-num' + id).hide('slow');
			$.ajax({
				type: "POST",
				url: "/func/delete.php",
				data: "id="+ id,
				success: function(xhr){
alert(xhr.responseText);
			},
error: function(xhr){
alert(xhr.responseText);
}
});
			alert(id);
	}

Make sure there is a response in your php code

<?
include ("../css/mysql.php");
session_start();
$id = htmlspecialchars(trim($_POST['id']));

$query= mysql_query("SELECT id_user FROM content WHERE id=$id");
$row= mysql_fetch_assoc($query);
$id_user= $row['id_user'];

if ($id_user==$_SESSION['iden'])
{
	$delete=mysql_query("UPDATE content SET delete='1' WHERE id=$id");
echo('success');
}else{
echo( 'selected user : '.$id_user.', session'.$_SESSION['iden']);  
}
?>

I used that method and i figured it out.

$delete=mysql_query("UPDATE content SET delete='1' WHERE id=$id");

It didn't like me Updating a column named delete so i changed the name and it fixed it.

good to hear. jQuery generally won't throw errors unless you ask it to.

You should probably mark this as solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.