onclick提交的数据库更新字段不起作用

时间:2014-05-15 15:19:00

标签: javascript php jquery html mysql

我正在尝试更新数据库中的列。用户将单击确认按钮,并向用户发送一封确认工作列表的电子邮件,同时更改列中的字段状态"已确认"到"是"。

我能够向用户发送电子邮件,但我不知道为什么列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>

1 个答案:

答案 0 :(得分:0)

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从数组

进行更新
$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 [&#39; order_ref&#39;]

$result = mysql_query("UPDATE Jobs SET confirmed = 'Yes' WHERE order_ref = '".$row['order_ref']."' ");