0

Hi, i have problem to save record and send email in php. After selecting the responsible person, the system supposed to save the responsible person in the database and then send email to notify the responsible person on his progress. The coding is below but it doesn't work. Please kindly advise. Thanks.

<?php
//error_reporting(E_ALL ^ E_NOTICE);

$cn=mysql_connect("localhost","user","") or die(mysql_error());
mysql_select_db("p",$cn) or die(mysql_error());

$sql = "SELECT * FROM user";
$rs = mysql_query($sql) or die(mysql_error());
echo "<select name='responsible2'>";

while($row = mysql_fetch_array($rs)) 

    { 

echo "<option value=".$row['Position'].">".$row['Position']."</option>";

    }
mysql_free_result($rs);
"</select>"; 

$q = "SELECT Email FROM user WHERE Position = '$responsible2'";
$r = mysql_query($q);
while($row = mysql_fetch_array($r))

    {
    echo "Email:".$row[Email]."<br/>";
    }

if(isset($_POST['Notify2']))

    {

$_SESSION['Progressid'];
echo $_SESSION['Progressid'];
$responsible2=$_POST['responsible2'];
echo $responsible2;
echo $_SESSION['Email'];
echo $_SESSION['Username']; 
$cemail2=$_POST['Email']; 

mysql_query("INSERT INTO improvement_plan (Responsible2,Progressid) VALUES ('" . $responsible2 . "',
'" .$_SESSION['Progressid'] . "')"); 
$Ipid = mysql_insert_id();

if(!empty($Ipid)) { 
$message = "New improvement plan added successfully"; 

require 'PHPMailer_5.2.4/PHPMailer_5.2.4/class.phpmailer.php';
$mail = new PHPMailer;

$mail->IsSMTP();                                     
$mail->Host = 'smtp.office365.com';   // Specify main and backup server
$mail->Mailer   = "smtp";
$mail->SMTPAuth = false; 

$mail->IsHTML(true);                                  // Set email format to HTML
$mail->ContentType = "text/html";

$mail->From =($_SESSION['Email']);                         
$mail->FromName =($_SESSION['Username']);   
$mail->AddAddress('$cemail2');               // Name is optional
$mail->Subject = 'system Notification';

$mail->Body    = 'Please do your <strong>Improvement Plan</strong>';

if(!$mail->Send())

    {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;

    }
else

    {
    echo 'Message has been sent'; 

    }  
    } 
    } 
?>

Edited by pritaeas: Fixed markdown.

3
Contributors
20
Replies
144
Views
2 Years
Discussion Span
Last Post by cereal
0

First of all, please use the 'code' function to put you code.
Then, the function mysql_query() is deprecated as of PHP 5.5.0 and the MySQLi or PDO_MySQL extension should be used instead.
After that, check if the $_POST['Notify2'] is valid, is the session variable is printed correctly? put the sql scripts into a variable and print it before execute, and paste the printed script to db manager to check if got any syntax error on queries. If still not working, add the mysql_query($sql) or die("Invalid query: " . mysql_error()); to cater the error message.

0

Hi, thanks for your reply. Have tried your suggestions above and the responsible person's email ie $cemail2 doesn't echo any value. Please advise. Thanks.

0

Then perhaps you should try check where the $_POST['Email'] is set in the submitting form. Check if the name of the element is set correctly including the capital case.

0

Hi, thanks for your advise. I've put the ".$row[Email]." as ".$row['Email']." but still can't get the $cemail2 value. Please advise. Thanks.

0

Err...Have you read my post actually? I pointed you to debug if the $_POST value is correct and have you done that? If done, post how you done and what is the result?

0

Hi, below is the debug. I've placed it after line 82 above. Really appreciate for your advise. Thanks a lot.

<html>
<head>
<TITLE>Debug</TITLE>
</head>
<body>
<?php

if ($_POST['Debug'] == "on")

   {   

?>
<PRE>
<?php

print_r($_POST);

?>
</PRE>
<?php

   }

?>
<p align="center"><?php echo $_POST['Email']?> <?php echo $_POST['responsible2']?></p>
</body>
</html>

0

Hi, sorry actually am new with php and am not sure whether the debug is correct. Please advise. Thanks.

0

My 'debug' actually means that echo out the data to view.

print_r($_POST);
echo "<br/>";
echo "$responsible2".$responsible2=$_POST['responsible2'];
echo "$cemail2".$cemail2=$_POST['Email'];

and post the debug result(echoed page) here for us to help

0

Hi, below is the debug but still no value echoed for $cemail2. Please kindly advise. Thanks.

if(isset($_POST['Notify2']))

{

$_SESSION['Progressid'];
echo $_SESSION['Progressid'];
$responsible2=$_POST['responsible2'];
$cemail2=$_POST['Email'];
echo $_SESSION['Email'];
echo $_SESSION['Username'];

print_r($_POST);
echo "<br/>";
echo "$responsible2".$responsible2=$_POST['responsible2'];
echo "$cemail2".$cemail2=$_POST['Email'];

0

That is the CODE, we need to view the result please. Errr....result? meaning printed values???? On screen printed value....

Edited by lps

0

Hi, after option selection and when i press Notify button,there is no printed values in the improvement plan table and still no email send. Please advise. Thanks.

0

Hi, attached is the result. Please advise. Thanks.

Attachments debug.png 16.13 KB
0

Hi, below is the form use to submit the POST. Please advise. Thanks.

<form name="progress" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<input type="hidden" name="Progressid" value="<?php echo $_SESSION['Progressid']; ?>" />
<table width="850" border="1">
  <tr align="center">
   <th width="70" scope="col">Item</th>
    <th width="120" scope="col">Business Enablers/ISO Clause</th>
    <th width="98" scope="col">Root Cause</th>
    <th width="79" scope="col">Corrective Action (CA)(Immediate action to rectify)</th>
    <th width="80" scope="col">Preventive Action (PA) (Action to prevent recurrence)</th>
    <th width="144" scope="col">Action Step (Break the PA into small and chronological steps)</th>
    <th width="80" scope="col">Responsible</th>
    <th width="120" scope="col">Timeline</th>
    <th width="98" scope="col">Resources (incl. cost in RM,if applicable)</th>
    <th width="79" scope="col">Progress of CA and PA</th>
    <th width="80" scope="col">Comment</th>
    <th width="144" scope="col">Status (On-going/Completed)</th>
 <input type="submit" name="Notify2" value="Notify"/> 
 </tr>   

<?php

$disable = '';
$i = 0;
$d = 0;

$con = mysql_connect("localhost","user","");
if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("p", $con);
$sql = "SELECT * FROM improvement_plan where Ipid='" . $Ipid . "'";
$res_list = mysql_query($sql);

if( isset( $_SESSION['Progressid'] ) )

{

$Progressid= $_SESSION['Progressid'];

//$message = "Record Modified Successfully";

}

while($row_list = mysql_fetch_array($res_list))

{
$i++;       

?>
<td align="center"><div name="Item2" id="Item2<?php echo $i; ?>"><?php if($row_list['Item2'] != '0000-00-00'){ echo ($row_list['Item2']); }else{ echo "-"; } ?></div></td>
<td align="center"><div name="Business2" id="Business2<?php echo $i; ?>"><?php if($row_list['Business2'] != '0000-00-00'){ echo ($row_list['Business2']); }else{ echo "-"; } ?></div></td>
<td align="center"><div name="Rootcause2" id="Rootcause2<?php echo $i; ?>"><?php if($row_list['Rootcause2'] != '0000-00-00'){ echo ($row_list['Rootcause2']); }else{ echo "-"; } ?></div></td>
<td align="center"><div name="Correctiveaction2" id="Correctiveaction2<?php echo $i; ?>"><?php if($row_list['Correctiveaction2'] != '0000-00-00'){ echo ($row_list['Correctiveaction2']); }else{ echo "-"; } ?></div></td>
<td align="center"><div name="Preventiveaction2" id="Preventiveaction2<?php echo $i; ?>"><?php if($row_list['Preventiveaction2'] != ''){ echo ucwords($row_list['Preventiveaction2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Actionstep2" id="Actionstep2<?php echo $i; ?>"><?php if($row_list['Actionstep2'] != '0000-00-00'){ echo ($row_list['Actionstep2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Responsible2" id="Responsible2<?php echo $i; ?>"><?php if($row_list['Responsible2'] != '0000-00-00'){ echo ($row_list['Responsible2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Timeline2" id="Timeline2<?php echo $i; ?>"><?php if($row_list['Timeline2'] != '0000-00-00'){ echo ($row_list['Timeline2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Resources2" id="Resources2<?php echo $i; ?>"><?php if($row_list['Resources2'] != '0000-00-00'){ echo ($row_list['Resources2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Progress2" id="Progress2<?php echo $i; ?>"><?php if($row_list['Progress2'] != '0000-00-00'){ echo ($row_list['Progress2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Comment2" id="Comment2<?php echo $i; ?>"><?php if($row_list['Comment2'] != '0000-00-00'){ echo ($row_list['Comment2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Status2" id="Status2<?php echo $i; ?>"><?php if($row_list['Status2'] != '0000-00-00'){ echo ($row_list['Status2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Progressid" id="Progressid<?php echo $i; ?>"><?php if($row_list['Progressid'] != '0000-00-00'){ echo ($row_list['Progressid']); }else{ echo '-'; } ?></div></td>
</tr>
<?php

} 

if($i == 0)

{

?>
<tr><td colspan="7">No data.</td></tr>
<?php

$disable = 'disabled="disabled"';

}

?>
<?php

if($row['Status2'] == 'buka'){ }

?>
<br>
</table>
</form>

0

Ok, the only form elements I see here are:

<form name="progress" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

    <input type="hidden" name="Progressid" value="<?php echo $_SESSION['Progressid']; ?>" />

    <input type="submit" name="Notify2" value="Notify"/>

</form>

So the only values you will get from the $_POST array are Progressid and Notify2:

Array
(
    [Progressid] => 4
    [Notify2] => Notify
)

In your current sources I see the block code to generate $_POST['responsible2'] in the receiving script, you should move that select to the form script and add an input field to enter the email address. Basically your form should look like this:

<form name="progress" method="post" action="">

    <input type="hidden" name="Progressid" value="4" />

    <label for="responsible2">Responsible</label>
    <select name="responsible2" id="responsible2">
        <option value="1">abc</option>
        <option value="2">def</option>
        <option value="3">ghi</option>
    </select>

    <label for="email">E-mail Address</label>
    <input type="email" name="Email" id="email" />

    <input type="submit" name="Notify2" value="Notify"/>

</form>

Only at this point you can start to receive data from the $_POST array, for example:

Array
(
    [Progressid] => 4
    [responsible2] => 1
    [Email] => name.surname@domain.tld
    [Notify2] => Notify
)

I suggest you to understand how forms are handled by PHP:

Then, if you still need help try to update your code and to paste it here correctly, please read the syntax helper:

0

Hi, thanks for your reply. This is the updated code but seems like i still can't send email and save record in the improvement plan table. Please advise. Thanks.

<form name="progress" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">

<input type="hidden" name="Progressid" value="<?php echo $_SESSION['Progressid']; ?>" />
<table width="850" border="1">
  <tr align="center">
   <th width="70" scope="col">Item</th>
    <th width="120" scope="col">Business Enablers/ISO Clause</th>
    <th width="98" scope="col">Root Cause</th>
    <th width="79" scope="col">Corrective Action (CA)(Immediate action to rectify)</th>
    <th width="80" scope="col">Preventive Action (PA) (Action to prevent recurrence)</th>
    <th width="144" scope="col">Action Step (Break the PA into small and chronological steps)</th>
    <th width="80" scope="col">Responsible</th>
 <?php

$cn=mysql_connect("localhost","user","") or die(mysql_error());
mysql_select_db("p",$cn) or die(mysql_error());

$sql = "SELECT * FROM user";
$rs = mysql_query($sql) or die(mysql_error());
echo "<select name='responsible2'>";

while($row = mysql_fetch_array($rs))

{

echo "<option value=".$row['Position'].">".$row['Position']."</option>";

}

mysql_free_result($rs);
"</select>";

if (isset($_POST['Notify2']))

{

$responsible2=$_POST['responsible2'];
$q = "SELECT Email FROM user WHERE Position = '".$responsible2."'";
$r = mysql_query($q) or die(mysql_error());
while($row = mysql_fetch_array($r))

   {

echo "Email:".$row['Email']."<br/>";

    } 

$_POST['Email']=$row['Email'];

} 

?>

    <th width="120" scope="col">Timeline</th>
    <th width="98" scope="col">Resources (incl. cost in RM,if applicable)</th>
    <th width="79" scope="col">Progress of CA and PA</th>
    <th width="80" scope="col">Comment</th>
    <th width="144" scope="col">Status (On-going/Completed)</th>
 <input type="submit" name="Notify2" value="Notify"/> 
 </tr>   

<?php

$disable = '';
$i = 0;
$d = 0;

$con = mysql_connect("localhost","user","");
if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("p", $con);
$sql = "SELECT * FROM improvement_plan where Ipid='" . $Ipid . "'";
$res_list = mysql_query($sql);

if( isset( $_SESSION['Progressid'] ) )

{

$Progressid= $_SESSION['Progressid'];

//$message = "Record Modified Successfully";

}

while($row_list = mysql_fetch_array($res_list))

{
$i++;       

?>
<td align="center"><div name="Item2" id="Item2<?php echo $i; ?>"><?php if($row_list['Item2'] != '0000-00-00'){ echo ($row_list['Item2']); }else{ echo "-"; } ?></div></td>
<td align="center"><div name="Business2" id="Business2<?php echo $i; ?>"><?php if($row_list['Business2'] != '0000-00-00'){ echo ($row_list['Business2']); }else{ echo "-"; } ?></div></td>
<td align="center"><div name="Rootcause2" id="Rootcause2<?php echo $i; ?>"><?php if($row_list['Rootcause2'] != '0000-00-00'){ echo ($row_list['Rootcause2']); }else{ echo "-"; } ?></div></td>
<td align="center"><div name="Correctiveaction2" id="Correctiveaction2<?php echo $i; ?>"><?php if($row_list['Correctiveaction2'] != '0000-00-00'){ echo ($row_list['Correctiveaction2']); }else{ echo "-"; } ?></div></td>
<td align="center"><div name="Preventiveaction2" id="Preventiveaction2<?php echo $i; ?>"><?php if($row_list['Preventiveaction2'] != ''){ echo ucwords($row_list['Preventiveaction2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Actionstep2" id="Actionstep2<?php echo $i; ?>"><?php if($row_list['Actionstep2'] != '0000-00-00'){ echo ($row_list['Actionstep2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Responsible2" id="Responsible2<?php echo $i; ?>"><?php if($row_list['Responsible2']!= '0000-00-00'){ echo ($row_list['Responsible2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Timeline2" id="Timeline2<?php echo $i; ?>"><?php if($row_list['Timeline2'] != '0000-00-00'){ echo ($row_list['Timeline2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Resources2" id="Resources2<?php echo $i; ?>"><?php if($row_list['Resources2'] != '0000-00-00'){ echo ($row_list['Resources2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Progress2" id="Progress2<?php echo $i; ?>"><?php if($row_list['Progress2'] != '0000-00-00'){ echo ($row_list['Progress2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Comment2" id="Comment2<?php echo $i; ?>"><?php if($row_list['Comment2'] != '0000-00-00'){ echo ($row_list['Comment2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Status2" id="Status2<?php echo $i; ?>"><?php if($row_list['Status2'] != '0000-00-00'){ echo ($row_list['Status2']); }else{ echo '-'; } ?></div></td>
<td align="center"><div name="Progressid" id="Progressid<?php echo $i; ?>"><?php if($row_list['Progressid'] != '0000-00-00'){ echo ($row_list['Progressid']); }else{ echo '-'; } ?></div></td>
</tr>
<?php

} 

if($i == 0)

{

?>
<tr><td colspan="7">No data.</td></tr>
<?php

$disable = 'disabled="disabled"';

}

?>
<?php

if($row['Status2'] == 'buka'){ }

?>
<br>
</table>
</form>

0

You're welcome. Let's try to simplify the task:

  1. you have a form to select a responsible, populated by user table
  2. basing on selection you get an email address from user table
  3. you insert the improvement_plan table
  4. you finally send an email

You're trying to do this on the same page, but it seems you're mixing the two different states of the script:

  1. the starting state: when the user has not chosen a responsible and the form has not been submitted;
  2. the ending state: when the form have been submitted, at this point you have sent the email, all the information you're trying to print to the client will be sent to the browser only after the script has been executed and on reload the new information will disappear.

So, as example, your script should look like this:

<?php

    session_start();

    # database connection
    $cn = mysql_connect("localhost","user","") or die(mysql_error());
    mysql_select_db("p", $cn) or die(mysql_error());

    # work on form POST request
    if(isset($_POST['Notify2']))
    {
        $responsible = filter_input(INPUT_POST, 'responsible2', FILTER_SANITIZE_STRING);

        # get the email address from user table
        $qry1 = mysql_query("SELECT * FROM user WHERE Position = '$responsible'");
        $row  = mysql_fetch_assoc($qry1);

        # set the variables
        $cemail2    = $row['Email'];
        $position   = $row['Position'];
        $progressID = $_SESSION['Progressid'];

        # insert into improvement_plan table
        $insert = mysql_query("INSERT INTO improvement_plan (Responsible2, Progressid) VALUES('$position', '$progressID')") or die(mysql_error());
        $Ipid = mysql_insert_id();

        # send the email
        if( ! empty($Ipid))
        {
            $message = "New improvement plan added successfully";

            # PHPMailer code here
            require 'PHPMailer_5.2.4/PHPMailer_5.2.4/class.phpmailer.php';

            $mail = new PHPMailer;
            $mail->IsSMTP();
            $mail->Host         = 'smtp.office365.com';     // Specify main and backup server
            $mail->Mailer       = "smtp";
            $mail->SMTPAuth     = false;
            $mail->IsHTML(true);                            // Set email format to HTML
            $mail->ContentType  = "text/html";
            $mail->From         = $_SESSION['Email'];
            $mail->FromName     = $_SESSION['Username'];
            $mail->AddAddress('$cemail2');                  // Name is optional
            $mail->Subject      = 'system Notification';
            $mail->Body         = 'Please do your <strong>Improvement Plan</strong>';

            if(!$mail->Send())
            {
                echo 'Message could not be sent.';
                echo 'Mailer Error: ' . $mail->ErrorInfo;
                exit;
            }

            else
            {
                echo 'Message has been sent';

                # here you should add the query
                # to the improvement_plan table based on $Ipid
                # as the general query below
            }

        }

    }

    # general queries
    $responsibles = mysql_query("SELECT * FROM user");

?>
<!DOCTYPE html>
<html>
<head>
    <title>Form test</title>
</head>
<body>

    <form method="post">

        <label for="responsible2">Responsible</label>
        <select name="responsible2" id="responsible2">
        <?php
            while($row = mysql_fetch_array($responsibles))
                echo "<option value=\"{$row['Position']}\">{$row['Position']}</option>";
        ?>
        </select>

        <input type="submit" name="Notify2" value="Notify"/>
    </form>

</body>
</html>

Try it like this, with your credentials and check if it works fine. Then try to add your table codes.

A suggestion: please when you paste the code here, highlight it and press TAB at least once, so the code will be correctly parsed, at the moment it's really difficult to read.

0

Hi, thanks a lot for your reply. For your info, i've changed the code as per your advise. Now the $cemail2 and $responsible2 display the correct value but still can't send email to the responsible person. And the responsible person record is not save/display in the improvement plan table. Please advise. Thanks.

<?php
error_reporting(E_ALL ^ E_NOTICE);
$cn=mysql_connect("localhost","user","") or die(mysql_error());
mysql_select_db("p",$cn) or die(mysql_error());

if(isset($_POST['Notify2'])){

//$responsibles = filter_input(INPUT_POST, 'responsible2', FILTER_SANITIZE_STRING);
$responsible2=$_POST['responsible2'];
echo $responsible2;

$q = "SELECT Email FROM user WHERE Position = '".$responsible2."'";
$r = mysql_query($q) or die(mysql_error());
while($row = mysql_fetch_array($r))
    {
echo "Email:".$row['Email']."<br/>";
    } 
echo $row['Email']; 

$_SESSION['Progressid'];
echo $_SESSION['Progressid'];
$cemail2=$row['Email'];
echo $cemail2;
echo $_SESSION['Email'];
echo $_SESSION['Username']; 

mysql_query("INSERT INTO improvement_plan (Responsible2,Progressid) VALUES ('" . $responsible2 . "','" . $_SESSION['Progressid'] . "')"); 
$Ipid = mysql_insert_id();

if(!empty($Ipid)) { 
$message = "New improvement plan added successfully"; 

require 'PHPMailer_5.2.4/PHPMailer_5.2.4/class.phpmailer.php';
$mail = new PHPMailer;
$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->Host = smtp.office365.com';   // Specify main and backup server
$mail->Mailer   = "smtp";
$mail->SMTPAuth = false; 
$mail->IsHTML(true);                                  // Set email format to HTML
$mail->ContentType = "text/html";
$mail->From =($_SESSION['Email']);                         
$mail->FromName =($_SESSION['Username']);   

$mail->AddAddress('$cemail2');                       // Name is optional

$mail->Subject = 'IPDS system Notification';
$mail->Body    = 'Please do your <strong>Improvement Plan</strong>';

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}else{
    echo 'Message has been sent'; 
}  
}
}
$responsibles = mysql_query("SELECT * FROM user");
?>
<form name="ipdprogress" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <input type="hidden" name="Progressid" value="<?php echo $_SESSION['Progressid']; ?>" />
    <table width="850" border="1">
      <tr align="center">
       <th width="70" scope="col">Ipid</th>
       <th width="70" scope="col">Item</th>
        <th width="120" scope="col">Business Enablers/ISO Clause</th>
        <th width="98" scope="col">Root Cause</th>
        <th width="79" scope="col">Corrective Action (CA)(Immediate action to rectify)</th>
        <th width="80" scope="col">Preventive Action (PA) (Action to prevent recurrence)</th>
        <th width="144" scope="col">Action Step (Break the PA into small and chronological steps)</th>
        <th width="80" scope="col">Responsible</th>
        <select name="responsible2" id="responsible2">
        <?php
            while($row = mysql_fetch_array($responsibles))
                echo "<option value=\"{$row['Position']}\">{$row['Position']}</option>";
        ?>
        </select>
        <th width="120" scope="col">Timeline</th>
        <th width="98" scope="col">Resources (incl. cost in RM,if applicable)</th>
        <th width="79" scope="col">Progress of CA and PA</th>
        <th width="80" scope="col">Comment</th>
        <th width="144" scope="col">Status (On-going/Completed)</th>
     <input type="submit" name="Notify2" value="Notify"/> 
     </tr>   
<?php 

    $disable = '';
    $i = 0;
    $d = 0;

$con = mysql_connect("localhost","user","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("p", $con); 
$sql = "SELECT * FROM improvement_plan where  Ipid='" . $Ipid . "'";
$res_list = mysql_query($sql);

if( isset( $_SESSION['Progressid'] ) ) {
 $Progressid= $_SESSION['Progressid'];


}
while($row_list = mysql_fetch_array($res_list)){
    $i++;       
?>  
 <td align="center"><div name="Ipid" id="Ipid<?php echo $i; ?>"><?php if($row_list['Ipid'] != '0000-00-00'){ echo ($row_list['Ipid']); }else{ echo '-'; } ?></div></td>
 <td align="center"><div name="Item2" id="Item2<?php echo $i; ?>"><?php if($row_list['Item2'] != '0000-00-00'){ echo ($row_list['Item2']); }else{ echo "-"; } ?></div></td>
 <td align="center"><div name="Business2" id="Business2<?php echo $i; ?>"><?php if($row_list['Business2'] != '0000-00-00'){ echo ($row_list['Business2']); }else{ echo "-"; } ?></div></td>
 <td align="center"><div name="Rootcause2" id="Rootcause2<?php echo $i; ?>"><?php if($row_list['Rootcause2'] != '0000-00-00'){ echo ($row_list['Rootcause2']); }else{ echo "-"; } ?></div></td>
 <td align="center"><div name="Correctiveaction2" id="Correctiveaction2<?php echo $i; ?>"><?php if($row_list['Correctiveaction2'] != '0000-00-00'){ echo ($row_list['Correctiveaction2']); }else{ echo "-"; } ?></div></td>
 <td align="center"><div name="Preventiveaction2" id="Preventiveaction2<?php echo $i; ?>"><?php if($row_list['Preventiveaction2'] != ''){ echo ucwords($row_list['Preventiveaction2']); }else{ echo '-'; } ?></div></td>
 <td align="center"><div name="Actionstep2" id="Actionstep2<?php echo $i; ?>"><?php if($row_list['Actionstep2'] != '0000-00-00'){ echo ($row_list['Actionstep2']); }else{ echo '-'; } ?></div></td>
 <td align="center"><div name="Responsible2" id="Responsible2<?php echo $i; ?>"><?php if($row_list['Responsible2']!= '0000-00-00'){ echo ($row_list['Responsible2']); }else{ echo '-'; } ?></div></td>
 <td align="center"><div name="Timeline2" id="Timeline2<?php echo $i; ?>"><?php if($row_list['Timeline2'] != '0000-00-00'){ echo ($row_list['Timeline2']); }else{ echo '-'; } ?></div></td>
 <td align="center"><div name="Resources2" id="Resources2<?php echo $i; ?>"><?php if($row_list['Resources2'] != '0000-00-00'){ echo ($row_list['Resources2']); }else{ echo '-'; } ?></div></td>
 <td align="center"><div name="Progress2" id="Progress2<?php echo $i; ?>"><?php if($row_list['Progress2'] != '0000-00-00'){ echo ($row_list['Progress2']); }else{ echo '-'; } ?></div></td>
 <td align="center"><div name="Comment2" id="Comment2<?php echo $i; ?>"><?php if($row_list['Comment2'] != '0000-00-00'){ echo ($row_list['Comment2']); }else{ echo '-'; } ?></div></td>
 <td align="center"><div name="Status2" id="Status2<?php echo $i; ?>"><?php if($row_list['Status2'] != '0000-00-00'){ echo ($row_list['Status2']); }else{ echo '-'; } ?></div></td>
 <td align="center"><div name="Progressid" id="Progressid<?php echo $i; ?>"><?php if($row_list['Progressid'] != '0000-00-00'){ echo ($row_list['Progressid']); }else{ echo '-'; } ?></div></td>
 </tr> 
<?php
} 
if($i == 0){
?>
<tr><td colspan="7">No data.</td></tr> 
<?php
    $disable = 'disabled="disabled"';
}
?>
<?php
if($row['Status2'] == 'buka'){ }
?> 
<br>
</table>
</form> 
0

Add or die(mysql_error()); to the insert query, it seems correct to me, so if it fails is because there could some constraint that is not satisfied, like a NOT NULL column not involved in the insert process.

So try:

mysql_query("INSERT INTO improvement_plan (Responsible2,Progressid) VALUES ('" . $responsible2 . "','" . $_SESSION['Progressid'] . "')") or die(mysql_error());

What error is returning PHPMailer? Are you sure this is correct?

$mail->SMTPAuth = false;

Usually when using an SMTP you should define username, password, encryption type, port to connect. At the moment I see that the sender will be the email defined in the $_SESSION array:

$mail->From =($_SESSION['Email']);          # sender
$mail->FromName =($_SESSION['Username']);
$mail->AddAddress('$cemail2');

So if the SMTP requires authentication, then you have to provide those values in relation to the sender email and this email must be allowed to connect that specific SMTP server, otherwise it will not work. An example of setup:

$mail->isSMTP();                        // Set mailer to use SMTP
$mail->Host = 'smtp1.example.com';      // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                 // Enable SMTP authentication
$mail->Username = 'user@example.com';   // SMTP username
$mail->Password = 'secret';             // SMTP password
$mail->SMTPSecure = 'tls';              // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;

Edited by cereal

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.