在我的数据库中,我有一个名为 user_items 的表,其中存储了每个用户名以及他们拥有的每个项目的数量。每次用户可以购买时,我都有一列,他们的用户名有一列。现在我也有一个 HTML 表单,并且想从 HTML 选择中进行 PDO 选择。
<?php
if (isset($_POST['Detach'])) {
// Here we get the info about the pokemon
$teamget = $db->prepare("select * from user_items where username = :name");
$teamget->execute(array(':name' => $_SESSION['username']));
$getteam = $teamget->fetch(); // Use fetchAll() if you want all results, or just iterate over the statement, since it implements Iterator
echo $getteam -> $_POST['item'];
echo "working";
}
?>
<form method="post" action="">
<select name="item" id="item" style="width:150px;padding-left:5px;">
<option value=""></option>
<option>poke_ball</option>
<option>great_ball</option>
<option>ultra_ball</option>
<option> aster_ball</option>
<option>potion</option>
<option>super_potion</option>
<option>hyper_potion</option>
<option>burn_heal</option>
<option>parlyz_heal</option>
<option>antidote</option>
<option>awakening</option>
<option>ice_heal</option>
<option>dawn_stone</option>
<option>dusk_stone</option>
<option>fire_stone</option>
<option>leaf_stone</option>
<option>moon_stone</option>
<option>oval_stone</option>
<option>shiny_stone</option>
<option>sun_stone</option>
<option>thunder_stone</option>
<option>water_stone</option>
<option>exp_share</option>
</select>
<select name="Detach" id="Detach" style="width:150px;padding-left:5px;">
<option value=""></option>
<option>Attach To Pokemon 1</option>
<option> Attach To Pokemon 2</option>
<option> Attach To Pokemon 3</option>
<option> Attach To Pokemon 4</option>
<option> Attach To Pokemon 5</option>
<option> Attach To Pokemon 6</option>
?>
</select>
<br/>
<br/>
<br/>
<br/>
<button name="submit" type="submit" id="Submit_Butt">Detach Item</button>
<p> </p>
<p> </p>
</form>
第一个选择是每列的名称。我要做的是选择列的值 where $_POST
= the column
这行得通吗?
$teamget = $db->prepare("select '".$_POST['item']."' from user_items where username = :name");
$teamget->execute(array(':name' => $_SESSION['username']));
$getteam = $teamget->fetch(); // Use fetchAll() if you want all results, or just iterate over the statement, since it implements Iterator
echo $getteam ;