【发布时间】:2016-12-09 07:14:47
【问题描述】:
您好,我有一个下拉列表,其中包含一个数据库表中的值 我想点击按钮将特定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 表中
谢谢
【问题讨论】:
-
@ManojSharma 全部由您的答案编辑和修复,但我收到此错误
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'chart' cannot be null' ( ! ) PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'chart' cannot be null -
谢谢大家帮助我解决了另一个想法,我想出了再次感谢