onclick提交上的数据库更新字段不起作用
Database update field on onclick submit doesn't work
我正在尝试更新我的数据库中的列。用户将点击确认按钮,并向用户发送一封确认任务列表的电子邮件,同时将"confirmed"列中的字段状态更改为"Yes"。
我能够发送电子邮件给用户,但我不知道为什么列id喜欢在我的数据库中更新不工作。
我的代码
php: <?php
ini_set("display_errors",1);
error_reporting(-1);
require("../controllers/cn.php");
include("/usr/share/php/Mail.php");
include("/usr/share/php/Mail/mime.php");
// Get the purchase order details
$query = mysql_query("SELECT Jobs.* FROM Jobs where job_status = 'Dispatched'") or die(mysql_error());
// Set the email content
$text = 'Text version of email';
$html .= '<html><body>';
$html .= '<p style="font-family: Arial, Helvetica, sans-serif; font-size: 22px; font-weight: bold; text-transform: uppercase; text-align: center;">Spineless Dispatch Summary</p>';
$html .= '<p style="font-family: Arial, Helvetica, sans-serif; font-size: 13px; text-align: center;">Please find below a summary of all dispatched orders: </p>';
$html .= '<table border="1" cellspacing="0" cellpadding="0" align="center"><tr><th width="200">Order Ref.</th><th width="200">First Name</th><th width="200">Last Name</th><th width="200">Tracking No.</th></tr>';
while($row = mysql_fetch_array($query)) {
$html .= '<tr>';
$html .= '<td style="padding: 10px;">'.$row['order_ref'].'</td>';
$html .= '<td style="padding: 10px;">'. $row['first_name'].'</td>';
$html .= '<td style="padding: 10px;">'.$row['last_name'].'</td>';
$html .= '<td style="padding: 10px;">'.$row['tracking_number'].'</td>';
$html .= '</tr>';
}
$html .= '</table></body></html>';
//$file = "/mnt/Jobs/Purchase_Orders/".date("Y", strtotime($row['created']))."/".date("F", strtotime($row['created']))."/PO".$row['id'].".pdf";
$crlf = "'n";
// Set customers email
$sendAddress = "rachelle@variouk.com";
// Set the from address
$hdrs = array(
'From' => 'rachelle@variouk.com',
'Subject' => 'Spineless System'
);
// Create the email
$mime = new Mail_mime(array('eol' => $crlf));
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
//$mime->addAttachment($file, 'application/pdf');
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
// Send the email
$mail =& Mail::factory('mail');
// Paper company address
$mail->send($sendAddress, $hdrs, $body);
// Production email address (production@variouk.com)
$mail->send("rachelle@variouk.com", $hdrs, $body);
// Update the sent status of the order
$result = mysql_query("UPDATE Jobs SET confirmed = 'Yes' WHERE order_ref = '".$order_ref."' ");
header("location: joblist.php");
?>
HTML: <div id="buttons" align="center">
<p style="padding-bottom: 15px; font-weight: bold; font-size: 14px;">Please confirm these jobs</p>
<button type="submit" class="btn btn-primary" onclick="javascript:window.location='email.php">Confirm</button>
<button class="btn btn-default btn-wide" onclick="javascript:window.location="'joblist.php'";>Cancel</button>
</div>
Edit2:
$order_refs = array();//array of orders to update in db.
while($row = mysql_fetch_array($query)) {
$html .= '<tr>';
$html .= '<td style="padding: 10px;">'.$row['order_ref'].'</td>';
$html .= '<td style="padding: 10px;">'. $row['first_name'].'</td>';
$html .= '<td style="padding: 10px;">'.$row['last_name'].'</td>';
$html .= '<td style="padding: 10px;">'.$row['tracking_number'].'</td>';
$html .= '</tr>';
$order_refs[]=$row['order_ref'];
}
并使用ref from array
进行更新$result = mysql_query("UPDATE Jobs SET confirmed = 'Yes' WHERE order_ref IN ('". implode("', '", $order_refs) ."') ");
让我知道它是否有效。
原始:尝试添加
if(!$result){
echo mysql_error();
}
后$result = mysql_query("UPDATE Jobs SET confirmed = 'Yes' WHERE order_ref = '".$order_ref."' ");
告诉我上面写了什么。我将更新我的答案,修复这个错误。(我现在还不能评论问题,信誉还很低)
编辑:正如@Santik指出的$order_ref在此代码中未定义,因此修复将使用$row['order_ref']$result = mysql_query("UPDATE Jobs SET confirmed = 'Yes' WHERE order_ref = '".$row['order_ref']."' ");
相关文章:
- 在visualforce中为更新字段分配HTML链接/按钮
- 反应:以动态生成的形式根据另一个字段更新字段值
- PHP通过AJAX更新字段值
- AngularJS:更改对象不会更新字段,但直接更改字符串会更新字段
- MongoDB:用反值更新字段编号
- MongoDB:将字段移动到新文档并更新字段和数组
- 为什么Javascript对象不更新字段
- 基于计算的自动更新字段
- 如何在流星中自动更新字段
- 我想在 VF 页面上选中复选框时更新字段
- 使用jquery don'更新字段;t更新可观察到的
- 在更改事件jquery上更新字段值
- 如何通过乘以字段值Mongodb来更新字段
- Javascript更新字段的总和
- 使用复选框自动更新字段
- 如何动态更新字段而不刷新和不调用服务器
- 如何使用REST API用新值更新字段
- 当用程序更新字段时,如何在更新时运行jquery函数
- 检查文本框是否已更改.如果是,更新字段
- Jquery,更新字段和启用按钮