[英]Select data from db table 1 and insert it into another db table 2 in php
[英]Insert into db table (query 2) from another table (query 1) in php
嗨,我有一个下拉列表,其中包含一个db表中的值,我想单击按钮以将特定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> 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个更正
缺少:
在INSERT
查询的VALUES
中。 更换uempPic
有:uempPic
。
INSERT
查询未执行。 在最后一个bindParam
语句之后添加以下行。
$q01->execute();
此行错误,请检查一下...
$q01 = $DB_con->prepare('INSERT INTO results01(chart,chartDescription,regNo,lastName,firstName,location,empPic) VALUES(:uchart, :uchartDescription, :uregNo, :ulastName, :ufirstName, :ulocation, :uempPic)');
请查看您的准备声明:
$ q01 = $ DB_con-> prepare('INSERT INTO results01(chart,chartDescription,regNo,lastName,firstName,location,empPic)VALUES(:uchart,:uchartDescription,:uregNo,:ulastName,:ufirstName,:ulocation,uempPic) ');
您忘了在“ uempPic”中添加“:”,请使用以下语句。
$ q01 = $ DB_con-> prepare('INSERT INTO results01(chart,chartDescription,regNo,lastName,firstName,location,empPic)VALUES(:uchart,:uchartDescription,:uregNo,:ulastName,:ufirstName,:ulocation,:uempPic )');
您尚未包括execute语句。 在bindParam之后添加以下语句。
$ q01-> execute();
我认为您的插入问题将得到解决。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.