向数据库提交下拉信息

时间:2014-10-20 01:00:48

标签: php mysql

我已经打破了多对多的关系,其中一个只持有一个叫做主题的表的主键,一个叫做粗略的Lectures。

我使用了mysql数据库的下拉列表,我只需要一些关于如何将两个下拉选项发送到单独的mysql表的指导。

<?php echo form_label('Lecturer :'); ?> 
<?php $sql = "select id, email from coarse_lecturers ";
$result = mysql_query($sql);
echo "<select email = 'sub1'>";
while ($row = mysql_fetch_array($result)){

echo"<option value = '" . $row['id'] . "'>" . $row['email'] . "</option>";


}
echo "</select>";

?>


<?php echo form_label('Subject_ID :'); ?> <?php echo form_error('subjectID'); ?>        
<?php $sql = "select subject_id,subject_name  from subjects ";
$result = mysql_query($sql);
echo "<select subject_name = 'sub1'>";
while ($row = mysql_fetch_array($result)){

    echo"<option value = '" . $row['subject_id'] . "'>" . $row['subject_name'] . "</option>";

}
echo "</select>";

?>


<?php echo form_submit(array('id' => 'submit', 'value' => 'Submit'));?>

1 个答案:

答案 0 :(得分:0)

搞定了,

  <?php echo form_label('Lecturer  :'); ?> <?php echo form_error('dname'); ?>
<select name="lecturer">
<option value="none" selected="selected">------------Select Lecturer------------</option>

<?php $sql = "select id, email from coarse_lecturers ";
$result = mysql_query($sql);
while ($row = mysql_fetch_array($result)){


    echo"<option value = '" . $row['id'] . "'>" . $row['email'] . "</option>";




    array('id' => 'lecturer', 'value' => 'lecturer');


}
echo "</select>";

?>