Don't forget to quote .$r['mobname'].
$name .="<option value=\"".$r['mobname']."\" >".$r['mobname']."</option>";
Your $_POST tests only .
if (isset($_POST["filter"])) {
$submittedValue = $_POST["filter"];
}
What about if $_POST["filter"] is NOT set ?
Your code did not take care of this fact. He always runs through the section $menu2.
Your $_POST is as the name implies, of a post. To evaluate a $_POST must be done a post.
<input type="submit" name="Submit" value="Submit" />
for example
$menu1 = "<form id='filter' name='filter' method='post' action=' '>
<p><label>Select Company</label></p>
<select name='filter' id='filter'>
" . $options . "
</select>
<input type=\"submit\" name=\"Submit\" value=\"Send\" />
</form>";
Put all the logic for the second menu in your code if (isset($_POST["filter"])) {
echo $menu1;
if (isset($_POST["filter"])) {
$submittedValue = $_POST["filter"];
if ($q2= ....)
{
mysqli_stmt_bind_param($q2,"s",$submittedValue);
$s=$submittedValue;
mysqli_stmt_execute($q2);
mysqli_stmt_bind_result($q2,$r);
while(mysqli_stmt_fetch($q2)) {
$name .="<option value=\"".$r['mobname']."\" >".$r['mobname']."</option>";
}
$menu2 = "<form id='moblist' name='moblist' method='post' action=' '>
<p><label>Select Mobile</label></p>
<select name='moblist' id='moblist'>
" . $name . "
</select>
</form>";
echo $menu2;
}
}
Update:
You can not use $r['mobname'] with a bind.
mysqli_stmt_bind_result($q2,$r);
....
while(mysqli_stmt_fetch($q2)) {
$name .="<option value=\"".$r['mobname']."\" >".$r['mobname']."</option>";
}
Use it like .
mysqli_stmt_bind_result($q2,$r);
....
while (mysqli_stmt_fetch($q2)) {
$name .="<option value=\"".$r."\" >".$r."</option>";
}
mysqli_stmt_close($q2);
Update 2
you forget to quote that to
$options .="<option value=". $row['compName'] ." >" . $row['compName'] . "</option>";
right
$options .="<option value=\"". $row['compName'] ."\" >" . $row['compName'] . "</option>";