dpgvdfg321041670 2015-03-27 06:35
浏览 19
已采纳

值未发布到数据库

I have created a form which includes dropdown boxes. After I make the selection and submit the values, they are not getting updated in the database. The code for the form is:

<form id="myForm" name="myForm" action='insert.php' method='post' >
<input type='hidden' name='st' value=0>


<table  style="text-align:center; width:100%">
<tr><td style="text-align:right"><label>Select SE/AE:</label></td><td style="text-align:left">        
<?php
        include "configs.php"; // Database connection using PDO
        //$sql="SELECT name,id FROM student"; 
        $sql="SELECT DISTINCT seae FROM se_ae "; //order by name
        /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
        echo "<select name=seae value='select one'>SE/AE</option>"; // list box select command
        foreach ($dbo->query($sql) as $row){//Array or records stored in $row
        echo "<option value=$row[id]>$row[seae]</option>"; 
        /* Option values are added by looping through the array */ 
        }
        echo "</select>";// Closing of list box
?> </td>


<tr><td style="text-align:right"><label>Select Brand:</label></td><td style="text-align:left"> 
<?php
        include "configs.php"; // Database connection using PDO
        //$sql="SELECT name,id FROM student"; 
        $sql="SELECT DISTINCT brand FROM se_ae "; //order by name
        /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
        echo "<select name=brand value='select one'>Brand</option>"; // list box select command
        foreach ($dbo->query($sql) as $row){//Array or records stored in $row
        echo "<option value=$row[id]>$row[brand]</option>"; 
        /* Option values are added by looping through the array */ 
        }
        echo "</select>";// Closing of list box
?> </td>


<tr><td style="text-align:right"><label>Select Territory:</label></td><td style="text-align:left">
<?php
        include "configs.php"; // Database connection using PDO
        //$sql="SELECT name,id FROM student"; 
        $sql="SELECT DISTINCT territory FROM se_ae "; //order by name
        /* You can add order by clause to the sql statement if the names are to be displayed in alphabetical order */
        echo "<select name='territory' id='territory' value=''>"; // list box select command
        foreach ($dbo->query($sql) as $row){//Array or records stored in $row
        echo "<option value=$row[id]>$row[territory]</option>"; 
        /* Option values are added by looping through the array */ 
        }
        echo "</select>";// Closing of list box
?> </td>
</form>

The code or the file that I am trying to post the value to the database with is:

<?php
$connection = mysql_connect("localhost", "root", ""); // Establishing Connection with Server
$db = mysql_select_db("kmcrg", $connection); // Selecting Database from Server// Establishing Connection with Server
if(isset($_POST['submit'])){ // Fetching variables of the form which travels in URL
$seae = $_POST['seae'];
$brand=$_POST['brand'];
$territory=$_POST['territory'];
$name=$_POST['name'];
$e_id=$_POST['number'];
$email = $_POST['email'];
$contact = $_POST['contact'];
if($name !=''||$email !=''){
//Insert Query of SQL
$query = mysql_query("insert into employees(seae,brand,territory,name,e_id,email,contact) values ('$seae','$brand','$territory','$name','$e_id', '$email', '$contact')");
header('location:list.php');
}
else{
echo "<p>Insertion Failed <br/> Some Fields are Blank....!!</p>";
}
}
?>

There are also other fields in the form like name, email, etc. They are getting updated but not the values from the combobox. Can anyone help?

  • 写回答

1条回答 默认 最新

  • dongxue7306 2015-03-27 06:48
    关注
    <?php
            include("configs.php");
            $sql="SELECT DISTINCT `seae` FROM se_ae ";
          ?>
            <select name="seae">
          <?php   foreach ($dbo->query($sql) as $row){?>
    
            <option value="<?php echo $row[id];?>">
                             <?php echo $row[seae];?></option> 
          <?php 
            }?>
            </select>
    

    try something like this..

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图