嗨,我有一个下拉列表,其中有一个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);
}
}你能帮我修一下吗?该按钮工作正常,但该值未存储在db表中。
谢谢
发布于 2016-12-09 07:20:18
PHP中的2处更正
VALUES of INSERT查询中缺少INSERT。将uempPic替换为:uempPic。INSERT查询。在最后一条bindParam语句之后添加下面一行。
$q01->execute();发布于 2016-12-09 07:19:02
请检查这一行的错误..。
$q01 = $DB_con->prepare('INSERT INTO results01(chart,chartDescription,regNo,lastName,firstName,location,empPic) VALUES(:uchart, :uchartDescription, :uregNo, :ulastName, :ufirstName, :ulocation, :uempPic)');发布于 2016-12-09 07:20:17
请看一看你的准备陈述:
$q01 =$DB_con->准备(‘插入到results01(图表,chartDescription,regNo,lastName,firstName,location,empPic)值(u图表,:uchartDescription,:uregNo,:ulastName,:ufirstName,:ulocation,uempPic)');
您忘记添加":“加上"uempPic",请使用下面的语句。
$q01 =$DB_con->准备(‘插入到results01(图表、chartDescription、regNo、lastName、firstName、位置、empPic)值(u图表,:uchartDescription,:uregNo,:ulastName,:ufirstName,:uempPic,:uempPic));
您没有包含execute语句。在bindParam之后添加下面的语句。
$q01->execute();
我想你的插入问题会解决的。
https://stackoverflow.com/questions/41055011
复制相似问题