Question

I am trying to update a column on my database. The user will click the confirm button and an email is sent to the user confirming a list of jobs and at the same time change the field status in column "confirmed" to "Yes".

I am able to send an email to the user but i have no clue as to why the column id like to update in my database doesn't work.

Here is my code

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>
Was it helpful?

Solution

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'];
}

And to update using ref from array

$result = mysql_query("UPDATE Jobs SET confirmed = 'Yes' WHERE order_ref IN ('". implode("', '", $order_refs) ."') ");

Let me know if it works.

Original:

Try adding

if(!$result){
 echo mysql_error();
}

after

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

And tell me what does it say. I'll update my answer with a fix for that error. (I cannot comment on Questions yet, still low reputation)

Edit: as @Santik noted $order_ref is not defined in this code, so the fix would be to use $row['order_ref']

$result = mysql_query("UPDATE Jobs SET confirmed = 'Yes' WHERE order_ref = '".$row['order_ref']."' ");
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top