Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从下拉列表中更新外键值_Php - Fatal编程技术网

Php 从下拉列表中更新外键值

Php 从下拉列表中更新外键值,php,Php,我正在尝试更新现有数据的值 当用户单击编辑图标时,他们将能够编辑数据 它们的下拉列表应该显示已经选择的值。我怎样才能解决这个问题 <form name="updateform" method="post" action="updateVehicleModel.php"> <div class="form-group"> <LABEL>Enter Vehicle Model</LABEL> <input type=

我正在尝试更新现有数据的值

当用户单击编辑图标时,他们将能够编辑数据

它们的下拉列表应该显示已经选择的值。我怎样才能解决这个问题

<form name="updateform" method="post" action="updateVehicleModel.php">
  <div class="form-group">
    <LABEL>Enter Vehicle Model</LABEL>
    <input  type="hidden" name="modelid" value="<?php if(isset($row['id_vehiclemodel'])) { echo $row['id_vehiclemodel']; } ?>" />
    <input type="text" name="model" value="<?php if(isset($row['vehicle_model'])) { echo $row['vehicle_model']; } ?>" required class="form-control col-md-3 col-sm-3" />
  </div>

  <div class="form-group">
    <label>Choose Vehicle Type</label>
    <input  type="hidden" name="modelid" value="<?php if(isset($row['id_vehiclemodel'])) { echo $row['id_vehiclemodel']; } ?>" />
    <select class="form-control" name="fkvehicleType" value="<?php if(isset($row['id_vehicleType'])){echo $row['vehicle_Type'];}?>">
      <option value="">Select Vehicle Type</option>
      <?php
        $res=mysqli_query($link,"Select * from vehicletype where status_vehicleType='1'");

        while ($row=mysqli_fetch_array($res)) {
          ?>
        <option value=<?php echo $row['id_vehicleType'];?>><?php echo $row['vehicle_Type'];?></option>
          <?php
        }

      ?>
    </select>
  </div>

  <div class="form-group">
    <label>Choose Vehicle Brand</label>

    <select class="form-control" name="fkvehicleBrand" value="<?php if(isset($row['id_vehicleBrand'])){echo $row['vehicle_Brand'];}?>">
        <option value="">Select Vehicle Brand</option>
    <?php
        $res=mysqli_query($link,"Select * from vehiclebrand where status_vehicleBrand='1'");

    while ($row=mysqli_fetch_array($res)) {
      ?>
    <option value=<?php echo $row['id_vehicleBrand'];?>><?php echo $row['vehicle_Brand'];?></option>
      <?php
    }

    ?>
    </select>
  </div>
  <div class="form-group">
    <label>Choose Status</label>
    <select name="statustype" value="<?php if(isset($row['vehicle_model'])) { echo $row['vehicle_model']; } ?>" required class="form-control">
      <option value="1">Enabled</option>
      <option value="0">Disabled</option>
    </select>
  </div>
  <div class="form-group">
    <input type="submit" name="submit" value="Update" class="btn btn-info btn-block" />
  </div>

  <span class="text-success"><?php if (isset($success)) { echo $success; } ?></span>
  <span class="text-danger"><?php if (isset($error)) { echo $error; } ?></span>

</form>

输入车型
>
选择汽车品牌
>
选择状态

解决了!我用了这个..感谢那些给我提供解决方案想法的人

<div class="form-group">
     <label>Choose Vehicle Type</label>
     <select class="form-control" name="vehicleType" value="<?php if(isset($row['id_vehicleType'])){echo $row['vehicle_Type'];}?>">
        <option value="">Select Vehicle Type</option>
        <?php 
        $res=mysqli_query($link,"Select * from vehicletype where status_vehicleType='1'");
       while ($row=mysqli_fetch_array($res)) {
         ?>
    <option value=<?php echo $row['id_vehicleType'];?> <?php if($_GET["typeid"]==$row['id_vehicleType']){ ?> selected<?php } ?>><?php echo $row['vehicle_Type'];?></option>
                <?php
                      }
                  ?>
            </select>
        </div>

选择车辆类型
已选择>

问题应该更清楚。如果任何用户正在编辑车辆,则应与用户表建立关系。您可以通过添加条件使用selected=selected使其加载上一个值。@teshvenk谢谢。这正是我想要的。然而,我在约会时遇到了同样的问题。我怎样才能解决这个问题?我的意思是,如何加载上一个日期值?