php - 这些值未发布到数据库

标签 php html database combobox sql-update

我创建了一个包含下拉框的表单。在我做出选择并提交值后,它们没有在数据库中更新。表单的代码是:

<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>

我试图将值发布到数据库的代码或文件是:

<?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>";
}
}
?>

表单中还有其他字段,如姓名、电子邮件等。它们正在更新,但不是来自组合框的值。谁能帮忙?

最佳答案

<?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>

尝试这样的事情..

关于php - 这些值未发布到数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29294683/

相关文章:

html - 移除框架滚动条

php - 动态和依赖形式

PHP 在现有 XML 文件上添加子项和属性

javascript - array.splice 不工作

php - 复制 WordPress 导航菜单

mysql - 包括数据库在内的单元测试应用程序太慢

php - 查询失败 您的 SQL 语法有错误;检查与您的 MariaDB 服务器版本相对应的手册以获取正确的语法

php - Codeigniter:使用 session 从另一个表获取用户数据

php - 如何使用多个表的数据格式化嵌套的json

MySQL 计算别名计数列的平均值