在我的數據庫中,我有一個名爲user_items的表,其中存儲了每個用戶名以及他們每個項目的數量。每個用戶都可以購買1列,併爲他們輸入用戶名。現在我也有一個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>
第一個select是每列的名稱。我想要做的是選擇列的值,其中$_POST
=列
這個工作嗎?
$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 ;
'session_start();'無疑在那裏,對嗎? –
是的,$ db connect – user2734610
知道了。所以新手們總是會留下這些信息。 –