我正在尝试使用输入的值更新数据库,但是当使用 jquery 的新图像时输入发生了变化,所以我想使用 php 获取输入的值并使用该值更新我的数据库,我我试过了,但到目前为止它只是用 0 更新行,即使我将 $_POST 更改为 $_GET,我该如何解决这个问题?
//Update the user team.
if (isset($_POST['f']) && $_POST['f'] == 'setTeam') {
$cid1 = $_POST['s0'];
$cid2 = $_POST['s1'];
$cid3 = $_POST['s2'];
$updateTeam = $db->query("UPDATE accounts SET cid1 = '$cid1', cid2 = '$cid2', cid3 = '$cid3' WHERE id = '$id'");
}
<div id="droppable_slots" class="current_team">
<div class="slot 1">1</div>
<input type="hidden" name="s0" value="">
<div class="slot 2">2</div>
<input type="hidden" name="s1" value="">
<div class="slot 3">3</div>
<input type="hidden" name="s2" value="">
</div>
更新后的版本:
if (isset($_POST['f']) && $_POST['f'] == 'setTeam') {
$cid1 = $_GET['s0'];
$cid2 = $_GET['s1'];
$cid3 = $_GET['s2'];
$updateTeam = $db->query("UPDATE accounts SET cid1 = '$cid1', cid2 = '$cid2', cid3 = '$cid3' WHERE id = '$id'");
}
<form id="droppable_slots" name="droppable_slots" method="POST">
<div class="slot 1">1</div>
<input type="hidden" name="s0" value="">
<div class="slot 2">2</div>
<input type="hidden" name="s1" value="">
<div class="slot 3">3</div>
<input type="hidden" name="s2" value="">
</form>