gpt4 book ai didi

php - if(isset($_POST ['Submit' ])) 未获取状态值

转载 作者:行者123 更新时间:2023-11-30 00:51:57 25 4
gpt4 key购买 nike

通过这个ajax函数,我首先填充下拉列表first_state.php*下面是完整代码的部分*

function showUser(str)
{
if (str=="")
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","get_district.php?q="+str,true);
xmlhttp.send();
}

这里我调用函数并获取第一个下拉列表的值

<form class="form2" name="form_pin" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="state" onchange="showUser(this.value)">
<option value="">Select State</option>
while ($row = mysql_fetch_array($result)){
echo "<option value='".$row['State']."'>".$row['State']."</option>";}
</form>

当调用下面的函数时,我没有获得地区的值(value)

if(isset($_POST['Submit']))
{
$state = $_POST["state"];
$district = $_POST["district"];
echo $state; echo $district;
}

将变量传递给 get_district.php 时填充的第二个下拉列表

<?php
include_once "connect_db.inc";
$q = $_GET['q'];
//echo $q;
$con = mysqli_connect($dbhost, $dbusername, $dbuserpassword);
if (!$con)
{
die('Could not connect: ' . mysqli_error($con));
}

mysqli_select_db($con,$default_dbname);
$sql="SELECT DISTRICT FROM state_district WHERE STATE = '".$q."'";
//$sql="SELECT * FROM state_district";

$result = mysqli_query($con,$sql);
?>
<select name="district">
<?PHP
while($row = mysqli_fetch_array($result))
{
echo "<option value='".$row['DISTRICT']."'>".$row['DISTRICT']."</option>";
}
?>
</select>
<?PHP
mysqli_close($con);
?>

我如何以一种形式采用 _post['district'] 和 _post['state'] ,上面的代码工作正常,但是我我一无所知。问题是我有两个 php 文件**

最佳答案

**You are not requesting the below code** 
------------------

<select name="district">
<?PHP
while($row = mysqli_fetch_array($result))
{
echo "<option value='".$row['DISTRICT']."'>".$row['DISTRICT']."</option>";
}
?>
</select>
-----------------------------

**to do so add ID with <select id="txtHint"></select> option in first_step.php**
--------------------------
<form class="form2" name="form_pin" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<select name="state" onchange="showUser(this.value)">
<option value="">Select State</option>
while ($row = mysql_fetch_array($result)){
echo "<option value='".$row['State']."'>".$row['State']."</option>";}
**// add below**
<select id="txtHint"></select>
</form>

关于php - if(isset($_POST ['Submit' ])) 未获取状态值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20897571/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com