SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Upadting data and then sned mail if certain field equal to certain data in php.

    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
    PHP 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>
    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.

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2005
    Location
    Aveiro, Portugal
    Posts
    164
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hi!

    Have you looked up PHP mail() function?
    You could call the function if your criterias are met.
    HTH
    Yours truely
    Mário Ramos

  3. #3
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    My requiremnet is, if $smpl_typ=pps and $smpl_cmnts=Approved then it will send auto mail to the user.
    added to what @mjpr ; said:

    PHP Code:

    $smpl_typ 
    'pps';
    $smpl_cmnts 'Approved';

    // create a conditional statement in your code

    if ( $smpl_typ === "pps"  &&  $smpl_cmnts === "Approved"){

    // now send your mail
    // mail($to, $from, $subject);
    echo 'sending mail!';



    ps if $smpl_typ really is shorthand for $simple_type and you think that is really the best way to write your variables then you are wrong. You are not gaining anything and you are losing legibility. I/you/we have to guess the names of variables is it $smple_typ OR $smpl_type OR $simpl_typ? You may as well stick to correctly spelled English -- or your mother tongue if you prefer. But I would advise avoiding this extra and totally unnecessary layer of obfuscation, you are not saving anything.

    Well, you had me guessing wrongly anyhow ...

  4. #4
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help.

    Will keep your advise & will follow in furture.

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Please see below,
    PHP Code:
    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.
    Attached Images Attached Images

  6. #6
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    Here is the basic flow you should be aiming for:

    PHP Code:
    // start message variable as an empty string 
    // somewhere BEFORE your loop starts
    $message "";

    // loop through your sql results as you have been doing

    while ( you have results){

    // use string concatenation .= to keep adding stuff to your $message var

    $message .= "some info";
    $message .= "some more info";

    }
    // now you loop has stopped ....

    // so then send one email.
    mail($to$subject$message); 

  7. #7
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Posts
    57
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Cups View Post
    Here is the basic flow you should be aiming for:

    PHP Code:
    // start message variable as an empty string 
    // somewhere BEFORE your loop starts
    $message "";

    // loop through your sql results as you have been doing

    while ( you have results){

    // use string concatenation .= to keep adding stuff to your $message var

    $message .= "some info";
    $message .= "some more info";

    }
    // now you loop has stopped ....

    // so then send one email.
    mail($to$subject$message); 
    Thanks, i have got solution.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •