<?php $con=mysqli_connect('localhost','root','password','swati');
$sql1="SELECT * FROM `country`";

?>


<html>
<head>
<script>
function val()
{
    var name=document.getElementById("name").value;
    var add=document.getElementById("add").value;
    var email=document.getElementById("email").value;
    var chk1=document.getElementById("c1").checked;
    //var chk2=document.getElementById("c").checked;
    //var chk3=document.getElementById("c3").checked;
    //var gen=document.getElementById("gender").checked;
    var gen1=document.getElementById("gender1").checked;
    if(name=="" || name==null)
    {
        alert("name can not be blank");
        return false;
        }

        if(add=="" || add==null)
    {
        alert("address can not be blank");
        return false;
        }
        if(email=="" || email==null)
    {
        alert("email id can not be blank");
        return false;
        }
    if(chk1==false)
    {
        alert("check atleast 1 box");
        return false;

        }
        if(gen1==false)
    {
        alert("check atleast 1 box");
        return false;

        }
    }


</script>
<script>
function state(str)
{
    //alert(str);
    var xmlhttp;
    if(str.length==0)
    {
        //var param="id=str";
        //var url=regstate.php;
        alert(str);
        document.getElementById("city").innerHTML=" ";
        return;
        }
        if(window.XMLHttpRequest)
        {
            xmlhttp=new XMLHttpRequest();
            }
            else
            {
                xmlhttp=ActiveXobject("Microsoft.XMLHTTP")
                }
        xmlhttp.onreadystatechange=function()
        {
            if(xmlhttp.readyState()==4 && xmlhttp.status==200)
            {
                document.getElementById("city").innerHTML=xmlhttp.responseText;
                }
            }

            xmlhttp.open("GET","regstate.php?id="+str,true);
            //xmlhttp.open("GET",url+"?"+param,true);
            xmlhttp.send();
    }




</script>
</head>

<body>
<form method="post" action="" enctype="multipart/form-data" onSubmit="return val();">
<table>
<tr>
<td>Name</td>
<td><input type="text" name="name" id="name" /></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="add" id="add" /></td>
</tr>
<tr>
<td>Email Id</td>
<td><input type="text" name="email" id="email" /></td>
</tr>
<tr>
<td>Check</td>
<td><input type="checkbox" name="c1" id="c1" /></td>
<td><input type="checkbox" name="c2" id="c1" /></td>
<td><input type="checkbox" name="c3" id="c1" /></td>
</tr>
<tr><td>select gender</td>
<td><input type="radio" name="gender" id="gender1" value="M" />M</td>
<td><input type="radio" name="gender" id="gender1" value="F" />F</td>
</tr>
<tr><td>Image</td>
<td><input type="file" name="img" /></td></tr>
<tr><td><input type="submit" name="submit" /></td></tr>
<tr><td><select name="select" id="country" onChange="state(this.value)">
<option value="">Select country</option>

<?php
$data=mysqli_query($con,$sql1);
while($row=mysqli_fetch_assoc($data))
{ ?>
<option value="<?php echo $row['id'];?>"><?php echo $row['country_name'];?></option>
<?php }?>
</select></td>

</tr>
</table>

</form>
</body>
<div id="city"><select><option value="">selectcity</option>
<option value="<?php echo $row['id'];?>"><?php echo $row['state_name'];?></option>
</select></div>
</html>
<?php

if(isset($_POST['submit']))
{
    $name=$_POST['name'];
    $add=$_POST['add'];
    $email=$_POST['email'];
    $check1=$_POST['c1'];
    $check2=$_POST['c2'];
    $check3=$_POST['c3'];

    $gen=$_POST['gender'];
    $imgname=$_FILES['img']['name'];
if($imgname!="")
{
    $target=mktime().$imgname;
    move_uploaded_file($_FILES['img']['tmp_name'],"images/".$target);
}


        $sql="INSERT INTO `employee_record`(`name`, `address`, `email`, `check1`, `check2`, `check3`, `gender`, `image`) VALUES ('$name','$add','$email','$check1','$check2','$check3','$gen','$target')";
        if(mysqli_query($con,$sql))
        {
            echo success;
            }

        }
?>

this is reg.php

<?php 
$id=$_GET['param'];
echo $id;
$con=mysqli_connect('localhost','root','password','swati');
$sql="select * from state where c_id='$id'";
?>
<select>
<option value=" ">selectcity</option>
<?php
$data=mysqli_query($con,$sql);
while($row=mysqli_fetch_array($data))
{echo $row['state_name'];
?>
<option value="<?php echo $row['id'];?>"><?php echo $row['state_name'];?></option>
</select>
<?php }?>

this is regstate.php
i want to pass this str to another page and fetch the state of relevant country in select box but this is not working please help
xmlhttp.open("GET","regstate.php?id="+str,true);

thi line is not working at all give solution

you run regstate.php?id=28 (chose any value that is valid) in browser, see what is output?
Fisrt check problem is in javsccript or ur process page itself

problem is in passing value from one page to another i am not getting id to next page
xmlhttp.open("GET","regstate.php?id="+str,true);
from this line i am passing id to regstate.php page but i am not getting id

On regstate.php line 2 you have

$id=$_GET['param'];

But according to line 81 in reg.php your variable is called id. So line 2 in regstate.php should be

$id=$_GET['id'];

yes i change this$id=$_GET['param'];
to $id=$_GET['id']; this but still not getting id to next page

// Check This Line See An Error
if(xmlhttp.readyState()==4 && xmlhttp.status==200)
// change this line Now ok
if(xmlhttp.readyState ==4 && xmlhttp.status==200)

xmlhttp.open("GET","regstate.php?id="+str,true);// ok
//now Recive The Value
 $id=$_GET['id'];
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.