【问题标题】:country city state insert issue国家城市国家插入问题
【发布时间】:2022-06-15 22:45:18
【问题描述】:

我创建了一个包含乡村城市状态下拉列表的表单,适合我的需求,就我而言:distrito、concelho、freguesia。 我有一张私人桌子,我会看到提交的表格并能够将它们下载到 Excel 中。 下拉菜单在前端工作,但是当我尝试使用所有其他数据提交表单时,乡村城市国家没有进入表格,如果有人可以帮助我,我不知道如何解决这个问题不胜感激。 提前致谢。

Here is the part of code of the program wich is not working to insert the values, i got form action directed to the code.php:
<label for="distrito">Distrito</label>
<select class="form-control" id="distrito-dropdown">
<option value="">Seleccione o distrito</option>
<?php
require_once "db.php";
$result = mysqli_query($conn,"SELECT * FROM distrito");
while($row = mysqli_fetch_array($result)) {
?>
<option value="<?php echo $row['id'];?>"><?php echo $row["distrito_dropdown"];?></option>
<?php
}
?>
</select>
</div>
<div class="form-group">
<label for="concelho">Seleccione o concelho</label>
<select class="form-control" id="concelho-dropdown">
</select>
</div>                        
<div class="form-group">
<label for="freguesia">Freguesia</label>
<select class="form-control" id="freguesia-dropdown">
</select>
</div>
</div>
</div>
</div>
</div> 
</div>
<script>
$(document).ready(function() {
$('#distrito-dropdown').on('change', function() {
var distrito_id = this.value;
$.ajax({
url: "concelho-by-distrito.php",
type: "POST",
data: {
distrito_id: distrito_id
},
cache: false,
success: function(result){
$("#concelho-dropdown").html(result);
$('#freguesia-dropdown').html('<option value="">Seleccione o concelho primeiro</option>'); 
}
});
});    
$('#concelho-dropdown').on('change', function() {
var concelho_id = this.value;
$.ajax({
url: "freguesia-by-concelho.php",
type: "POST",
data: {
concelho_id: concelho_id
},
cache: false,
success: function(result){
$("#freguesia-dropdown").html(result);
}
});
});
});
</script>
----------------------------------------------------------------------------------------------
Here's the file code.php wich is where the form is submited through:
<?php
if(isset($_POST['save_data']))  
{  
$host="localhost";//host name  
$username="root"; //database username  
$word="";//database word  
$db_name="blog";//database name  
$tbl_name="tabela2"; //table name 
$con=mysqli_connect("$host", "$username", "$word","$db_name")or die("cannot connect");//connection string  
  $distrito = $_POST['distrito'];
    $concelho = $_POST['concelho'];
    $freguesia = $_POST['freguesia'];
    $origem = $_POST['origem'];
    $destino = $_POST['destino'];

$query = "INSERT INTO tabela2 (distrito,concelho,freguesia,origem,destino) VALUES ('$distrito','$concelho','$freguesia','$origem','$destino')";
    $query_run = mysqli_query($con, $query);

 
´´´

【问题讨论】:

  • 请将您的代码格式化为人类可读的。这将帮助您作为人类阅读和理解自己的代码。

标签: mysql insert dropdown country


猜你喜欢
  • 1970-01-01
  • 2017-10-20
  • 2011-01-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多