状态更改按钮单击php mysql PDO
我正在尝试更改MySQL表中接收到的包状态,我猜操作执行得不好,请有人发现错误,我正在粘贴下面的代码 当我将操作代码放入while循环时,它会将所有记录的状态更改为Received。但是当我把它放在while循环之外时,什么也没有发生状态更改按钮单击php mysql PDO,php,Php,我正在尝试更改MySQL表中接收到的包状态,我猜操作执行得不好,请有人发现错误,我正在粘贴下面的代码 当我将操作代码放入while循环时,它会将所有记录的状态更改为Received。但是当我把它放在while循环之外时,什么也没有发生 <table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example"> <thead>
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
<thead>
<tr>
<th>Customer Email</th>
<th>Shipping Company</th>
<th>Delivery Date</th>
<th>Tracking ID</th>
<th>Destination Address</th>
<th>Destination ZIP</th>
<th>Mark As Recieved</th>
</tr>
</thead>
<tbody>
<?php
require('config.php');
$conn = new PDO("mysql:host=".$DB_HOST.";dbname=".$DB_NAME,$DB_USER,$DB_PASS);
$sql = "SELECT * FROM packages_to_be_shipped_on_bremail_address";
$q = $conn->prepare($sql);
$q->execute();
$q->bindColumn(2, $custemail);
$q->bindColumn(3, $shipcompany);
$q->bindColumn(4, $deliverydate);
$q->bindColumn(5, $trackingid);
$q->bindColumn(6, $destaddress);
$q->bindColumn(7, $destzip);
$q->bindColumn(8, $status);
while($q->fetch()){
?>
<tr class="odd gradeX">
<td><?php echo $custemail ; ?></td>
<td><?php echo $shipcompany; ?></td>
<td><?php echo $deliverydate; ?></td>
<td><?php echo $trackingid; ?></td>
<td><?php echo $destaddress; ?></td>
<td><?php echo $destzip; ?></td>
<td>
<?php
if($status == "Pending") {
echo "
<form action='#' method='post' name='updatestatus'>
<input type='submit' name='submit' value='Mark As Recieved' />
</form>
";
}
else {
echo "Recieved";
}
}
?>
</td>
</tr>
<?php
$status = "Recieved";
if(isset($_POST['submit'])){
while($q->fetch()) {
$sql = "UPDATE packages_to_be_shipped_on_bremail_address SET status=? WHERE cust_email=?";
$q = $conn->prepare($sql);
$q->execute(array($status,$custemail));
header('Location:cust_orders.php');
}
}
?>
</tbody>
</table>
客户电子邮件
航运公司
交货日期
跟踪ID
目的地址
目的地邮政编码
标记为收到
您需要定义电子邮件,请尝试以下操作:
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
<thead>
<tr>
<th>Customer Email</th>
<th>Shipping Company</th>
<th>Delivery Date</th>
<th>Tracking ID</th>
<th>Destination Address</th>
<th>Destination ZIP</th>
<th>Mark As Recieved</th>
</tr>
</thead>
<tbody>
<?php
require('config.php');
$conn = new PDO("mysql:host=".$DB_HOST.";dbname=".$DB_NAME,$DB_USER,$DB_PASS);
$sql = "SELECT * FROM packages_to_be_shipped_on_bremail_address";
$q = $conn->prepare($sql);
$q->execute();
$q->bindColumn(2, $custemail);
$q->bindColumn(3, $shipcompany);
$q->bindColumn(4, $deliverydate);
$q->bindColumn(5, $trackingid);
$q->bindColumn(6, $destaddress);
$q->bindColumn(7, $destzip);
$q->bindColumn(8, $status);
while($q->fetch()){
?>
<tr class="odd gradeX">
<td><?php echo $custemail ; ?></td>
<td><?php echo $shipcompany; ?></td>
<td><?php echo $deliverydate; ?></td>
<td><?php echo $trackingid; ?></td>
<td><?php echo $destaddress; ?></td>
<td><?php echo $destzip; ?></td>
<td>
<?php
if($status == "Pending") {
echo "
<form action='#' method='post' name='updatestatus'>
<input type='submit' name='submit' value='Mark As Recieved' />
<input type='hidden' name='cust_email' value='<?php echo $custemail; ?>' />
</form>
";
}
else {
echo "Recieved";
}
}
?>
</td>
</tr>
<?php
$status = "Recieved";
if(isset($_POST['submit'])){
while($q->fetch()) {
$sql = "UPDATE packages_to_be_shipped_on_bremail_address SET status=? WHERE cust_email=?";
$q = $conn->prepare($sql);
$q->execute(array($status,$_POST['cust_email']));
header('Location:cust_orders.php');
}
}
?>
</tbody>
客户电子邮件
航运公司
交货日期
跟踪ID
目的地址
目的地邮政编码
标记为收到
请找到正确输出的正确代码
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
<thead>
<tr>
<th>Customer Email</th>
<th>Shipping Company</th>
<th>Delivery Date</th>
<th>Tracking ID</th>
<th>Destination Address</th>
<th>Destination ZIP</th>
<th>Mark As Recieved</th>
</tr>
</thead>
<tbody>
<?php
require('config.php');
$conn = new PDO("mysql:host=".$DB_HOST.";dbname=".$DB_NAME,$DB_USER,$DB_PASS);
$sql = "SELECT * FROM packages_to_be_shipped_on_bremail_address";
$q = $conn->prepare($sql);
$q->execute();
$q->bindColumn(1, $pid);
$q->bindColumn(2, $custemail);
$q->bindColumn(3, $shipcompany);
$q->bindColumn(4, $deliverydate);
$q->bindColumn(5, $trackingid);
$q->bindColumn(6, $destaddress);
$q->bindColumn(7, $destzip);
$q->bindColumn(8, $status);
while($q->fetch()){
?>
<tr class="odd gradeX">
<td><?php echo $custemail ; ?></td>
<td><?php echo $shipcompany; ?></td>
<td><?php echo $deliverydate; ?></td>
<td><?php echo $trackingid; ?></td>
<td><?php echo $destaddress; ?></td>
<td><?php echo $destzip; ?></td>
<td>
<?php
if($status == "Pending") {
echo "
<form action='#' method='post' name='updatestatus'>
<input type='hidden' name='pid' value='$pid'>
<input class='btn btn-inverse' type='submit' name='submit' value='Mark As Recieved'><i class='icon-refresh icon-white'></i></input>
</form>
";
}
else {
echo "Recieved";
}
}
?>
</td>
</tr>
<?php
$status = "Recieved";
if(isset($_POST['submit'])){
$sql = "UPDATE packages_to_be_shipped_on_bremail_address SET status=? WHERE package_id=?";
$q = $conn->prepare($sql);
$q->execute(array($status,$_POST['pid']));
header('Location:cust_orders.php');
}
?>
</tbody>
</table>
客户电子邮件
航运公司
交货日期
跟踪ID
目的地址
目的地邮政编码
标记为收到
这不应该从1
开始复制吗<代码>$q->bindColumn(2$custemail)
@Fred ii-最有可能的列1
是行id
,OP不想检索/返回该行。我的印象是PDO需要遵循@SeanNo序列,而不是字段。它们是否都具有相同的值->id=1客户电子邮件=name@email.com,id=2客户电子邮件=name@email.com等。
如果每个记录的cust_email
值相同,则需要在更新中使用id
或其他唯一值。
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
<thead>
<tr>
<th>Customer Email</th>
<th>Shipping Company</th>
<th>Delivery Date</th>
<th>Tracking ID</th>
<th>Destination Address</th>
<th>Destination ZIP</th>
<th>Mark As Recieved</th>
</tr>
</thead>
<tbody>
<?php
require('config.php');
$conn = new PDO("mysql:host=".$DB_HOST.";dbname=".$DB_NAME,$DB_USER,$DB_PASS);
$sql = "SELECT * FROM packages_to_be_shipped_on_bremail_address";
$q = $conn->prepare($sql);
$q->execute();
$q->bindColumn(1, $pid);
$q->bindColumn(2, $custemail);
$q->bindColumn(3, $shipcompany);
$q->bindColumn(4, $deliverydate);
$q->bindColumn(5, $trackingid);
$q->bindColumn(6, $destaddress);
$q->bindColumn(7, $destzip);
$q->bindColumn(8, $status);
while($q->fetch()){
?>
<tr class="odd gradeX">
<td><?php echo $custemail ; ?></td>
<td><?php echo $shipcompany; ?></td>
<td><?php echo $deliverydate; ?></td>
<td><?php echo $trackingid; ?></td>
<td><?php echo $destaddress; ?></td>
<td><?php echo $destzip; ?></td>
<td>
<?php
if($status == "Pending") {
echo "
<form action='#' method='post' name='updatestatus'>
<input type='hidden' name='pid' value='$pid'>
<input class='btn btn-inverse' type='submit' name='submit' value='Mark As Recieved'><i class='icon-refresh icon-white'></i></input>
</form>
";
}
else {
echo "Recieved";
}
}
?>
</td>
</tr>
<?php
$status = "Recieved";
if(isset($_POST['submit'])){
$sql = "UPDATE packages_to_be_shipped_on_bremail_address SET status=? WHERE package_id=?";
$q = $conn->prepare($sql);
$q->execute(array($status,$_POST['pid']));
header('Location:cust_orders.php');
}
?>
</tbody>
</table>