当我的页面加载时,它有一个带有隐藏输入的表单,名为“email”。此输入值等于登录用户电子邮件的输入值,并在页面加载时自动加载此值。
如何在下拉菜单中根据电子邮件显示列数据作为选择?
这就是我要做的事情:
http://oi61.tinypic.com/258tmhd.jpg
继承我的代码无效:
<html>
<header>
</header>
<body>
<?php
// Create the connection to the database
$con=mysqli_connect("xxx","xxx","xxx","xxx");
// Check if the connection failed
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
die();
}
$query = "SELECT itemname FROM seguin_orders";
$result = mysqli_query($con,$query);
?>
<select name="xxx"><option value="">-- Select One --</option>
while($row = mysqli_fetch_array($result))
{
echo("<option value=". $row['itemname'] . ">". $row['itemname'] ."</option>");
}
</select>
<form action="/demoform/contact_form.php" class="well" id="contactForm" method="post" name="sendMsg" novalidate="">
<input type="text" required id="mile" name="mile" placeholder="Miles"/>
</br>
<input id="email" name="email" placeholder="Email" required="" type="text" value="demo@gmail.com" readonly="readonly"/>
</br>
<input id="name" name="itemname" placeholder="ITEM NAME 1" required="" type="text" />
</br>
<input type="reset" value="Reset" />
<button type="submit" value="Submit">Submit</button>
</form>
</body>
</html>
答案 0 :(得分:1)
您可以编写一个servlet来获取包含request.getParameter(email)
SQL语句应该是这样的(使用preparedstatement):
SELECT itemname FROM table_A WHERE email=?
然后使用ps.setString(1, email);
设置您的String,执行查询,将结果传递给arraylist,然后将它们转发回您想要显示结果的jsp。
另见here