以下是我正在做的事情,我有2个数据库表:
我使用列表框填充它们,我可以从MySQL数据库中检索数据。我使用表单发布数据,然后捕获它。这是我的代码:
<form action="share.php" method="post">
Camera Name:
<select>
<?php
while($fetch_options1 = mysql_fetch_array($data1)) { //Loop all the options retrieved from the query
?>
<option id ="<?php echo $fetch_options1['id']; ?>" value="<?php echo $fetch_options1['name']; ?>"><?php echo $fetch_options1['name']; ?></option>
<?php
}
?>
</select>
Share With Email ID:
<select>
<?php
while($fetch_options = mysql_fetch_array($data)) {
?>
<option id ="<?php echo $fetch_options['id']; ?>" value="<?php echo $fetch_options['email']; ?>"><?php echo $fetch_options['email']; ?></option>
<?php } ?>
</select>
<input type="submit" name="submit" value="Share The camera">
</form>
在同一页面上,我使用此代码获取已发布的值,但这并未给出任何答案:
<?php
// START FORM PROCESSING
if (isset($_POST['submit'])) { // Form has been submitted.
$errors = array();
$_POST= array('name'=>'','email'=>'');
echo $cname = $_POST['name'];
echo $email1 = $_POST['email'];
echo $user_id=$_SESSION['id'];
} else { // Form has not been submitted.
}
?>
我想在用户点击提交时从列表框中获取所选的电子邮件ID和名称。我做错了什么?
答案 0 :(得分:1)
命名您的SELECT:
<SELECT name="selCamera" id="selCamera">
...
</SELECT>
<SELECT name="selEmail" id="selEmail">
...
</SELECT>
然后在你的PHP中:
$camera=$_POST['selCamera'];
$email=$_POST['selEmail'];
我不明白为什么你在做$_POST=array(...
事情,如果你选择这个解决方案就把它留下来。