Jump to content

Upadting Data And Then Sned Mail If Certain Field Equal To Certain Data In Php.


mehidy

Recommended Posts

Hi

 

I am using belo scrip to update my data & its working fine. But i need to send auto mail after updating the data.

Here is my code

 

Code>

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head>

<style type="text/css">

 

body {

margin:50px 0px; padding:0px;

text-align:center;

font:13px Tahoma,Geneva,sans-serif

}

 

#content {

width:1200px;

margin:0px auto;

text-align:left;

padding:15px;

border:0px dashed #333;

background-color:#eee;

}

</style>

<link rel="icon" href="http://www.mysite.com/favicon.ico" type="image/vnd.microsoft.icon" />

</head>

<body>

<div id='content'><h3><center>Success! </center></h3>

<table width='100%' border='0' cellspacing='1' cellpadding='0'>

<tr>

<td>

<table width='100%' border='0' cellspacing='1' cellpadding='1'>

<tr>

 

<td align='center'><strong>ID</strong></td>

<td align='center'><strong>SAMPLE TYPE</strong></td>

<td align='center'><strong>SAMPLE SIZE</strong></td>

<td align='center'><strong>SAMPLE COLOR</strong></td>

<td align='center'><strong>SAMPLE QTY</strong></td>

<td align='center'><strong>SUB NO</strong></td>

<td align='center'><strong>RTS/TTS</strong></td>

<td align='center'><strong>SENT ON</strong></td>

<td align='center'><strong>C.RCV ON</strong></td>

<td align='center'><strong>COMMENTS</strong></td>

<td align='center'><strong>REMARKS</strong></td>

</tr>

<?php

error_reporting(0);

require("connect.php");

// find out how many records there are to update

$size = count($_POST['tbl_smpl_id']);

 

// start a loop in order to update each record

$i = 0;

while ($i < $size) {

// define each variable

$tbl_smpl_id = $_POST['tbl_smpl_id'][$i];

$smpl_typ = $_POST['smpl_typ'][$i];

$smpl_size = $_POST['smpl_size'][$i];

$smpl_col = $_POST['smpl_col'][$i];

$smpl_qty = $_POST['smpl_qty'][$i];

$smpl_subno = $_POST['smpl_subno'][$i];

$smpl_rtstts = $_POST['smpl_rtstts'][$i];

$smpl_senton = $_POST['smpl_senton'][$i];

$cmnts_rcvon = $_POST['cmnts_rcvon'][$i];

$smpl_cmnts = $_POST['smpl_cmnts'][$i];

$smpl_rmks = $_POST['smpl_rmks'][$i];

 

// do the update and print out some info just to provide some visual feedback

 

$query = "UPDATE `tbl_smpl` SET

`smpl_typ` = '$smpl_typ',

`smpl_size` = '$smpl_size',

`smpl_col` = '$smpl_col',

`smpl_qty` = '$smpl_qty',

`smpl_subno` = '$smpl_subno',

`smpl_senton` = '$smpl_senton',

`cmnts_rcvon` = '$cmnts_rcvon',

`smpl_cmnts` = '$smpl_cmnts',

`smpl_rmks` = '$smpl_rmks',

`smpl_rtstts` = '$smpl_rtstts'

WHERE `tbl_smpl_id` = '$tbl_smpl_id' LIMIT 1";

mysql_query($query) or die ("Error in query: $query");

print "

 

<tr>

<td align='center'><p>$tbl_smpl_id</p></td>

<td align='center'>$smpl_typ</td>

<td align='center'>$smpl_size</td>

<td align='center'>$smpl_col</td>

<td align='center'>$smpl_qty</td>

<td align='center'>$smpl_subno</td>

<td align='center'>$smpl_rtstts</td>

<td align='center'>$smpl_senton</td>

<td align='center'>$cmnts_rcvon</td>

<td align='center'>$smpl_cmnts</td>

<td align='center'>$smpl_rmks</td>

</tr>

";

++$i;

}

mysql_close();

?>

<tr>

<td colspan='13' align='center'>

<input value="HOME" type="button" onclick="window.location.href='dano.php'">

<input value="GO2 ALL VIEW" type="button" onclick="window.location.href='vod0011.php'">

<input value="del" type="button" onclick="window.location.href='ddcolupdateano.php?col_tbl_order_id=<?php echo $id; ?>'">

</td>

</tr>

</table>

</td>

</tr>

 

</table>

</div>

</body>

</html>

code>

My requiremnet is, if $smpl_typ=pps and $smpl_cmnts=Approved then it will send auto mail to the user.

Kindly advise any suggestion or any example to achive my requirement.

Link to comment
Share on other sites

Hi. First of all I do not recommend doing ...

error_reporting(0);

simply because if any errors were to occur, you wouldn't know. Also, what I recommend you to look at is http://php.net/mail, this is a function that allows you to send emails.

 

You could start off with something like the following...

 

if ( $smpl_typ == "pps" && $smpl_cmnts == "Approved" ) {
$mail = mail ( . . . ); // Here you would create/send your email using the function I linked you to before.

if ( $mail )
echo 'An email was sent to your address.';
else
echo 'An error occurred whilst sending the email.';
}

 

Hopefully this will send you in the right direction.

 

In future when you paste code, please make sure you use code or php bbcode tags.

Edited by JLT
Link to comment
Share on other sites

Hi I am sending mail using following script & its working.

 

if ( $smpl_typ == "PPS" && $smpl_cmnts == "Approved" ){
$buyh = $_POST['buyh'];
$buyr = $_POST['buyr'];
$artstyl_no = $_POST['artstyl_no'];

$to = 'mehidy@yahoo.com' . ', '; // note the comma
$to .= 'sultan@yahoo.com';
// subject
$subject = "$smpl_typ comments of Buyer:$buyr Style:$artstyl_no";
// message
$message = "
<p>
Dear All<br>Please find below the sample comments for your ref of styel $artstyl_no!</p>
<table>
<tr>
 <th>Style</th><th>Color</th><th>Sub Date</th><th>Comments Date</th><th>Comments</th><th>Remarks</th>
</tr>
<tr>
 <td>$artstyl_no</td><td>$smpl_col</td><td>$smpl_senton</td><td>$cmnts_rcvon</td><td>$smpl_cmnts</td><td>$smpl_rmks</td>
</tr>

</table>
<p>This is an auto generated mail, no need to reply.</p>
<p>Thanking you<br>noreplay@yahoo.com<br>C</p>
";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: rayhan@yahoo.com, liton@yahoo.com' . "\r\n";
$headers .= 'To: reza@yahoo.com, bikash@yahoo.com' . "\r\n";
$headers .= 'From: Crosswear <mehidy@yahoo.com>' . "\r\n";
$headers .= 'Cc: zahid@yahoo.com, zahir@yahoo.com' . "\r\n";
$headers .= 'Cc: ajay@yahoo.com' . "\r\n";
$headers .= 'Bcc: mehidy1984@gmail.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
}

My probelm is here, because there will be multiple row, but its only contain the las row in the mail, $smpl_typ can be double row or more. Please see picture for better undersatnding.Kindly advise.

<tr>
 <td>$artstyl_no</td><td>$smpl_col</td><td>$smpl_senton</td><td>$cmnts_rcvon</td><td>$smpl_cmnts</td><td>$smpl_rmks</td>
</tr>

post-130823-0-58790700-1349239484_thumb.gif

Link to comment
Share on other sites

You need to take this bit:

<tr>
        <td>$artstyl_no</td><td>$smpl_col</td><td>$smpl_senton</td><td>$cmnts_rcvon</td><td>$smpl_cmnts</td><td>$smpl_rmks</td>
</tr>

Put a loop around it, where you go through every matched row. Then you only need to adjust the variables to use the current row, before you add it all to the $message variable.

 

Since I don't know where you're getting your rows from, or even the structure of that data, I cannot give you any more details on how to do this. I recommend checking out the PHP manual on control structures, if you're having problems understanding how to set this up.

Link to comment
Share on other sites

I'm guessing that because you directly takes the data from $_POST['buyh'] (and r) that there is only one lot of data coming through to the script, but from the code you've shown, we wont know if that's true or not. Other than that, as Christian F. said, a loop would be necessary.

Link to comment
Share on other sites

You need to take this bit:

<tr>
<td>$artstyl_no</td><td>$smpl_col</td><td>$smpl_senton</td><td>$cmnts_rcvon</td><td>$smpl_cmnts</td><td>$smpl_rmks</td>
</tr>

Put a loop around it, where you go through every matched row. Then you only need to adjust the variables to use the current row, before you add it all to the $message variable.

 

Since I don't know where you're getting your rows from, or even the structure of that data, I cannot give you any more details on how to do this. I recommend checking out the PHP manual on control structures, if you're having problems understanding how to set this up.

 

Hi thanks for your information.I am getting all the data from a update form. Here is my update form.

<?php
require("connect.php");
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

print "<table width='100%' border='0' cellspacing='1' cellpadding='0'><tr><td>";
print "<form name='namestoupdate' method='post' action='update5.php'>
<input type='hidden' name='buyr' value='$f005' />
<input type='hidden' name='artstyl_no' value='$f003' />
<table width='100%' border='0' cellspacing='1' cellpadding='1'>
<tr bgcolor='#FDEEF4'>
<td align='center'>*</td>
<td align='center'><strong>SAMPLE TYPE.$f005.</strong></td>
<td align='center'><strong>SAMPLE SIZE</strong></td>
<td align='center'><strong>SAMPLE COLOR</strong></td>
<td align='center'><strong>SAMPLE QTY</strong></td>
<td align='center'><strong>SUB NO</strong></td>
<td align='center'><strong>RTS/TTS</strong></td>
<td align='center'><strong>SENT ON</strong></td>
<td align='center'><strong>C.RCV ON</strong></td>
<td align='center'><strong>COMMENTS</strong></td>
<td align='center'><strong>REMARKS</strong></td>
</tr>\n";
$result = mysql_query("SELECT * FROM tbl_smpl WHERE smpl_tbl_order_id='$id'");
$size = count($_POST['tbl_smpl_id']);
$i = 0;
while ($Update = mysql_fetch_array($result)) {
print "</tr>\n";
print "<td align='center'><input type='hidden' name='tbl_smpl_id[$i]' value='{$Update['tbl_smpl_id']}' /></td>";
print "<td align='center'><input type='text' size='8px' name='smpl_typ[$i]' value='{$Update['smpl_typ']}' /></td>";
print "<td align='center'><input type='text' size='20px' name='smpl_size[$i]' value='{$Update['smpl_size']}' /></td>\n";
print "<td align='center'><input type='text' size='30' name='smpl_col[$i]' value='{$Update['smpl_col']}' /></td>\n";
print "<td align='center'><input type='text' size='10' name='smpl_qty[$i]' value='{$Update['smpl_qty']}' /></td>\n";
print "<td align='center'><input type='text' size='10' name='smpl_subno[$i]' value='{$Update['smpl_subno']}' /></td>\n";
print "<td align='center'><input type='text' size='15' name='smpl_rtstts[$i]' value='{$Update['smpl_rtstts']}' /></td>\n";

print "<td align='center'><input type='text' size='15' name='smpl_senton[$i]' value='{$Update['smpl_senton']}' /></td>\n";
print "<td align='center'><input type='text' size='8' name='cmnts_rcvon[$i]' value='{$Update['cmnts_rcvon']}' /></td>\n";
print "<td align='center'><input type='text' size='15' name='smpl_cmnts[$i]' value='{$Update['smpl_cmnts']}' /></td>\n";
print "<td align='center'><input type='text' size='15' name='smpl_rmks[$i]' value='{$Update['smpl_rmks']}' /></td>\n";

print "</tr>\n";
// add 1 to the count, close the loop, close the form, and the mysql connection
++$i;
}
print "<tr>
<td colspan='13' align='center'><input type='submit' value='submit' />";
print"</td>
</tr>
</table>
</td>
</tr>
</form>
</table>";
mysql_close();
?>

Edited by mehidy
Link to comment
Share on other sites

In that case you'll need a foreach () loop on $_POST['tbl_smpl_id'], where you extract both the key and the value. Then you'll need to use the key to reference the correct row from the other arrays you've created, to get the correct value from them.

 

Please show me an example.

Link to comment
Share on other sites

Hi I am trying to get the solution in another way. Please see below,

if ( $smpl_typ == "PPS" && $smpl_cmnts == "Approved" ){
require("connect.php");
$buyh = $_POST['buyh'];
$buyr = $_POST['buyr'];
$artstyl_no = $_POST['artstyl_no'];
$tbl_orderid = $_POST['tbl_orderid'];
$details = "SELECT smpl_col, smpl_subno, smpl_senton, cmnts_rcvon, smpl_cmnts, smpl_rmks FROM tbl_smpl WHERE  smpl_tbl_order_id='$tbl_orderid' AND smpl_typ='PPS' AND smpl_cmnts='Approved'";
$details_result = mysql_query( $details)
   or die ( "Couldn't get Products: ".mysql_error() );
while ( $det_row = mysql_fetch_array ( $details_result ) )
{
// message
$message = " <p>Dear All<br>Please find below the sample comments for your ref of styel $artstyl_no!</p>
 <table>
   <tr>
  <th>Color</th><th>Sub no</th><th>Sub Date</th><th>Comments Date</th><th>Comments</th><th>Remarks</th>
   </tr>
<tr><td> ".$det_row[ 'smpl_col' ]."</td>
   <td> ".$det_row[ 'smpl_subno' ]."</td>
  <td> ".$det_row[ 'smpl_senton' ]."</td>
  <td> ".$det_row[ 'cmnts_rcvon' ]."</td>
  <td> ".$det_row[ 'smpl_cmnts' ]."</td>
  <td> ".$det_row[ 'smpl_rmks' ]."</td></tr>	

 </table><p>This is an auto generated mail, no need to reply.</p><p>Thanking you<br>noreplay@yahoo.com<br>C</p>
";
$to  = 'mehidy@yahoo.com' . ', '; // note the comma
//$to .= 'sultan@yahoo.com';
// subject
$subject = "$smpl_typ comments of Buyer:$buyr Style:$artstyl_no";
// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
//$headers .= 'To: reza@yahoo.com, liton@yahoo.com' . "\r\n";
$headers .= 'From: C <mehidy@yahoo.com>' . "\r\n";
//$headers .= 'Cc: zahir@yahoo.com' . "\r\n";
//$headers .= 'Bcc: mehidy1984@gmail.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
}
}

By using above script, after updating. i am getting two mail for two row from my mysql table. but i want to get two row details in one mail. Plz see my requirement as attached.

post-130823-0-13903000-1349378302_thumb.gif

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.