hello, i just created a deletion php ajaxed script... i am facing a little problem, you see the deletion of the item is done successfuly, but it always delete the final record ( last id in MySQL db ) why is that ? here's my code :
Select.php
<?php
$conn = mysql_connect("localhost","root","");
if (!$conn)
{
die("Could Not Connect To The Database Server : " . mysql_error());
}
mysql_select_db("ajax", $conn);
$sql = mysql_query("SELECT * FROM gb");
if ( $sql && $conn )
{
while ( $row = mysql_fetch_array($sql) )
{
echo "ID : " . $row["id"] . "<br />";
echo "Name : " . $row["name"] . "<br />";
echo "<a href=\"javascript: process()\">Delete It</a><p></p>";
?>
<script type="text/javascript">
<!--
var url = "delete.php?id=<?php echo $row["id"]; ?>";
//-->
</script>
<?php
}
}
else
{
echo "Error : ". mysql_error();
}
mysql_close($conn);
?>
<script type="text/javascript">
<!--
function GetXmlHttpObject()
{
var xmlHttp = null;
try
{
xmlHttp = new XmlHttpRequest();
}
catch (e)
{
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}
var xmlHttp;
/*
function con()
{
var con = window.confirm("Are You Sure ?");
if ( con == true )
{
process();
}
else
{ }
}
*/
function process()
{
xmlHttp = GetXmlHttpObject();
if ( xmlHttp == null )
{
alert("Your Browser Does Not Support HTTP Requests");
}
xmlHttp.onreadystatechange = function statechanged()
{
if ( xmlHttp.readyState == 4 || xmlhttp.readyState == "complete" )
{
alert(xmlHttp.responseText);
}
}
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
}
//-->
</script>
hey ignore the commented confirmation function...
delete.php
<?php
$conn = mysql_connect("localhost","root","");
if (!$conn)
{
die("Could Not Connect To The Database Server : " . mysql_error());
}
mysql_select_db("ajax", $conn);
$sql = "DELETE FROM gb WHERE id = ". $_GET['id'];
if ( mysql_query($sql, $conn) )
{
echo "Post Deleted!!";
}
else
{
echo "Could Not Be Delete The Post!!";
}
mysql_close($conn);
?>
Regards