Thursday, 26 February 2015

How to Dropdownlist in Data select And Delete with Ajax


Select_ajax.php
============
<script>
function hi(str)
{
    if(window.XMLHttpRequest)
    {
   
        xml=new XMLHttpRequest();
       
    }
    xml.onreadystatechange=function()
    {
       
        if(xml.readyState == 4 && xml.status==200)
        {
            document.getElementById("msg").innerHTML=xml.responseText;
            }
        }
       
        xml.open("GET","select_ajax1.php?id="+str,true);
        xml.send();
}

</script>
<select name="sel" onChange="hi(this.value)">
<option>select</option>
<?php
mysql_connect("localhost","root","");
mysql_select_db("work");

$sql=mysql_query("select * from registration");
while($row=mysql_fetch_array($sql))
{
    echo "<option value=".$row[0].">".$row[1]."</option>" ;
}
 ?>


</select>
<span id="msg"></span>


=====

select_ajax1.php
========
<?php
$name=$_GET['id'];
echo $name;

mysql_connect("localhost","root","");
mysql_select_db("work");

$sql=mysql_query("delete from registration where id=$name");


?>
=========

No comments:

Post a Comment