php - 从 php 中的另一个表(查询 1)插入数据库表(查询 2)

标签 php html mysql dropdown

您好,我有一个下拉列表,其中包含一个数据库表中的值 我想单击按钮将特定 id 的行保存在另一个表中 我有这个表格

<table class="table table-bordered table-responsive">
    <tr>
    <td><label class="control-label">Drop down list</label></td>
    <td class="col-xs-4">
        <?php
            $stmt01 = $DB_con->prepare('SELECT * FROM dbtable WHERE chart in (458,459,461) ORDER BY id ASC');
            $stmt01->execute();
            if($stmt01->rowCount() > 0)
            {
            ?>
                <select class="form-control" name="value01">
                    <?php
                        while($row=$stmt01->fetch(PDO::FETCH_ASSOC))
                        {
                            extract($row);
                            echo '<option value="'.$row['id'].'">'.$row['id'].' '.$row['lastName'].' '.$row['firstName'].'</option>';
                        }
                    ?>
                </select>
            <?php
            }
            ?>
        </td>
        <td colspan="2" align="right" class="col-md-2"><button type="submit" name="btnsave01" class="btn btn-default">
            <span class="glyphicon glyphicon-save"></span> &nbsp; Insert
            </button>
        </td>
    </tr>

我的 php 是

require_once 'dbconfig.php';
if (isset($_POST['btnsave01']))
{
    if (isset($_POST['value01']))
    {
        $chart = $_GET['chart'];
        $chartDescription = $_GET['chartDescription'];
        $lastName = $_GET['lastName'];
        $firstName = $_GET['firstName'];
        $location = $_GET['location'];
        $empPic = $_GET['empPic'];

        $q01 = $DB_con->prepare('INSERT INTO results01(chart,chartDescription,regNo,lastName,firstName,location,empPic) VALUES(:uchart, :uchartDescription, :uregNo, :ulastName, :ufirstName, :ulocation, uempPic)');
        $q01->bindParam(':uchart',$chart);
        $q01->bindParam(':uchartDescription',$chartDescription);
        $q01->bindParam(':uregNo',$regNo);
        $q01->bindParam(':ulastName',$lastName);
        $q01->bindParam(':ufirstName',$firstName);
        $q01->bindParam(':ulocation',$location);
        $q01->bindParam(':uempPic',$empPic);
    }
}

你能帮我解决这个问题吗? 该按钮工作正常,但该值未存储在数据库表中

谢谢

最佳答案

PHP 中的 2 处更正

  1. INSERT 查询的 VALUES 中缺少 :。将 uempPic 替换为 :uempPic

  2. INSERT 查询未执行。在最后一个 bindParam 语句后添加以下行。

    $q01->execute();
    

关于php - 从 php 中的另一个表(查询 1)插入数据库表(查询 2),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41055011/

相关文章:

jquery - 我想使用 Jquery 添加三个按钮

javascript - 以异步方式运行的 Canvas 绘图函数

mysql - 优化 MySQL 导入(将详细的 SQL 转储转换为快速的一个/使用扩展插入)

php - 有没有一种有效的方法将包含代码片段的博客条目插入MySQL数据库?

html - 并排显示两个 div

MySQL:使用另一个映射表从旧表向新表插入值

mysql - Group By 子句不显示相同的行值?

php - 添加的数据仅在重新启动 Internet Explorer 后显示

PHP 不返回数据库项

php - Phinx迁移SQLSTATE[42S01] : Base table or view already exists: