【发布时间】:2015-07-02 05:14:55
【问题描述】:
这会将“customers.id”发送到另一个 php 文件:
echo '<a class="btn btn-primary" href="createworkorder.php?id='.$row['id'].'">Add Workorder</a>';
这会提取刚刚发送的 id 日期:
$id = null;
if ( !empty($_GET['id'])) {
$id = $_REQUEST['id'];
}
if ( null==$id ) {
header("Location: customers.php");
}
这会查看值/并从额外的工作订单表格中插入数据:
$id = $POST['name'];
$date = $_POST['date'];
$installer = $_POST['installer'];
$salesman = $_POST['salesman'];
$category = $_POST['category'];
$status = $_POST['status'];
if ($valid) {
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO workorder (date, installer, salesman, category, status) values(?, ?, ?, ?, ?)";
$q = $pdo->prepare($sql);
$q->execute(array( $id,$date,$installer,$salesman,$category,$status));
Database::disconnect();
header("Location: workorders.php");
}
<form class="form-horizontal" action="createworkorder.php" method="post">
<div class="control-group <?php echo !empty($dateError)?'error':'';?>">
<label class="control-label">Date</label>
<div class="controls">
<input name="date" type="text" placeholder="Date" value="<?php echo !empty($date)?$date:'';?>">
<?php if (!empty($dateError)): ?>
<span class="help-inline"><?php echo $dateError;?></span>
<?php endif; ?>
</div>
</div>
<div class="control-group <?php echo !empty($installerError)?'error':'';?>">
<label class="control-label">Installer</label>
<div class="controls">
<input name="installer" type="text" placeholder="Installer" value="<?php echo !empty($installer)?$installer:'';?>">
<?php if (!empty($installerError)): ?>
<span class="help-inline"><?php echo $installerError;?></span>
<?php endif;?>
</div>
</div>
出于某种奇怪的原因,看起来一切都在执行(没有错误),但我的工作订单表中没有显示任何数据。这是应该发生的事情
- 从用户选择中提取customers.id,并存储到workorder.name中
- 从表单中提取额外信息(日期/安装人员/销售人员/等),并使用所有数据插入工作订单表。
有没有人看看是否有一些愚蠢的东西导致这种情况不会发生?
【问题讨论】:
-
我不明白 POST 数据的来源。可能很明显,但我没有在那里连接点。请解释一下。
-
“id”来自一个单独的 php 文件,该文件处理客户表,“id”将作为“名称”插入到工作订单表中。我可以使用 Firefox 中的 Web 开发人员工具来查看它是否从该页面中提取了正确的信息,所以我认为问题与我的插入语句有关?