0

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");
}
?>

Edited by winnzor: n/a

3
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by vsmash
0

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

0

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']);  
}
?>
0

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.

0

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

You should probably mark this as solved.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.