如果我从品牌插入宝马汽车,我有数据库。例如,如何用sql更新id_make whith来自宝马的id。(我知道代码是一个很大的混乱,没有对齐)
http://i.stack.imgur.com/GQQg1.png
这是我的表格:
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add Car:</h4>
</div>
<div class="modal-body ">
<form action="index.php?page=carlist" method="POST" autocomplete="off">
<div class="form-group">
<label for="marca">Marca:</label>
<!-- <input type="text" class="form-control" name="marca" placeholder="Marca" data-toggle="modal" data-target="#marca"> -->
<div class="input-group">
<div class="input-group-btn">
<input type="text" class="form-control dropdown-toggle " data-toggle="dropdown" placeholder="
<?php
if (!isset($brd['name']))
{
echo "Brand";
} else
echo $brd['name'];
?>" name="marca" readonly="readonly">
<ul class="dropdown-menu scrollable">
<?php foreach ($brds as $brd)
{ ?>
<li><a href='#'><?php echo $brd['name']; ?></a></li>
<?php } ?>
</ul>
</div>
<!-- /btn-group -->
</div>
<!-- /input-group -->
</div>
<div class="form-group">
<label for="model">Model:</label>
<input type="text" class="form-control" name="model" placeholder="Model">
</div>
<div class="form-group">
<label for="color">Color:</label>
<input type="test" class="form-control" name="color" placeholder="Color">
</div>
<div class="form-group">
<label for="release_date">Release date:</label>
<div class=" date">
<input type="date" class="form-control" name="release_date" placeholder="Release date"
id='release_date'>
<!-- <span class="input-group-addon add-on"><span class="glyphicon glyphicon-calendar"></span></span> -->
</div>
</div>
<div class="form-group">
<label for="Value">Value:</label>
<input type="test" class="form-control" name="value" placeholder="Value">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
<input type="submit" name="addCar" class="btn btn-primary" value="Add car">
</div>
</form>
</div>
</div>
(来自品牌输入的php是显示来自db的所有品牌)
当我从列表中选择品牌并放入模型,颜色,价值,发布日期时我按添加汽车然后php在db上建立连接然后我在表模型上插入汽车的模型然后我需要添加在列表中选择品牌巫婆车的ID,然后用车辆的ID更新车型id_make。
答案 0 :(得分:0)
也许您需要使用以下方式请求您刚刚插入的品牌的ID:
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label>Search:
<input id="search-box" type="text"/>
</label>
然后,您将获得刚刚插入的记录的ID,并将该ID用于其他表中的make。