Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everyone, am trying to save records into improvement_plan table and then send email to the responsible person. Upon selection of Responsible2 from combobox, the program suppose to save the Responsible2 into improvement_plan table and then send email notification to that person. However, i was not able to save and send the email. Please advise. Thanks a lot.

PHP
error_reporting(E_ALL ^ E_NOTICE);
$con = mysql_connect("localhost","user","");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("pq",$con);
$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['Email'].">".$row['Position']."</option>";

$responsible2=$row['Position'];
echo $responsible2;
}
mysql_free_result($rs);
"</select>"; 
 
if(isset($_POST['Notify2'])){

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

 $result = mysql_query($query) OR die(mysql_error()); 
}
if(!empty($result)) {	

$useremail=$_SESSION['Email'];
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 ='$useremail';  
$mail->FromName =$_SESSION['Username'];	
$mail->AddAddress($row['Email']);               // Name is optional

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

if(!$mail->Send()) {
   echo 'Message could not be sent.';
   echo 'Mailer Error: ' . $mail->ErrorInfo;
   exit;
}else{
	echo 'Message has been sent'; 
} 
?>
<form name="ipdprogress" method="post" action="<?php echo $_SERVER['PHP_SELF']; ??>">
    <input type="hidden" name="Progressid" value="<?php echo $progressid; ??>" />
    <table width="850" border="1">
      <tr align="center">
      	<th width="80" scope="col">Responsible</th>
        <input type="submit" name="Notify2" value="Notify" /> 
	 </tr> 
	 </form>
<?php <br mode="hold" /?>
    $disable = '';
    $i = 0;
    $d = 0;

$con = mysql_connect("localhost","user","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("pq", $con);	
$sql = "SELECT * FROM improvement_plan where  Ipid='" . $Ipid . "'";
$res_list = mysql_query($sql);
if( isset( $_SESSION['Progressid'] ) ) {
 $progressid= $_SESSION['Progressid'];
//mysql_query("INSERT INTO improvement_plan (Responsible2 VALUES ('" . $_SESSION["Position"] . "')"); 
//$message = "Record Modified Successfully";  
  }
while($row_list = mysql_fetch_array($res_list)){
    $i++;		
?>  
 <tr><td align="center"><div id="Responsible2<?php echo $i; ?>"><?php if($row_list['Responsible2'] != '0000-00-00'){ echo ($row_list['Responsible2']); }else{ echo '-'; } ??></div></td></tr>
 <tr><td align="center"><div id="Progressid<?php echo $i; ?>"><?php if($row_list['Progressid'] != '0000-00-00'){ echo ($row_list['Progressid']); }else{ echo '-'; } ??></div></td></tr>
  
} 
if($i == 0){
?>
<tr><td colspan="7">No data.</td></tr> 
    $disable = 'disabled="disabled"';
}
?>
if($row['Status2'] == 'buka'){ }
?> 
<br>
</br></table>
</form>
Posted
Updated 24-Mar-15 20:09pm
v2
Comments
W Balboos, GHB 25-Mar-15 14:17pm    
What do you mean "your weren't able to"? If you had an error, please advise us as to what it is; if no error, what does happen?
Member 10738621 25-Mar-15 21:29pm    
Hi, thanks for your reply. When i choose the combobox selection, there is no data of Responsible2 being save to mysql database and no display of Responsible2 in improvement_plan table on the form. Also no email is being send to the Responsible2 person. Please advise. Thanks.
W Balboos, GHB 26-Mar-15 7:24am    
Since, from above, you're appear to have nothing happening from within the code you show it brings up two questions:

1) The attached code shows how you wish to save the data and send the email, BUT: How do you get to this page? Submitting a form? AJAX? other?

2) You mention combobox. PHP doesn't have a combobox control. Either you meant a select element or you're using some extension libraries. If the latter, you should specify them so someone with appropriate familiarity will be able to respond.

Member 10738621 26-Mar-15 21:28pm    
Hi, wrt your questions:
1) I get to this page by using Notify2 button from the form below.

<form name="ipdprogress" method="post" action="">
<input type="hidden" name="Progressid" value="" />
<table width="850" border="1">
<tr align="center">
<th width="80" scope="col">Responsible</th>
<input type="submit" name="Notify2" value="Notify" />
</tr>
</form>

<td align="center"><div id="Responsible2"></div></td>
<td align="center"><div id="Progressid"></div></td>
</tr>
<br>
</table>
</form>

2) Sorry, its actually select option for user to select the Responsible2 person.

Please advise and thanks a lot.
ramyajaya 27-Mar-15 8:23am    
Since it is a post method instead of $_SESSION['Progressid'] it should have $_POST['Progressid']

Make that change and try

1 solution

For a start, data submitted via a <form> is not retrieved using $_SESSION but by using $_REQUEST.
 
Share this answer
 
Comments
Member 10738621 27-Mar-15 23:20pm    
Hi, have tried using $_REQUEST['Progressid'] but still no data being save and no email sent. Please advise. Thanks a lot.
W Balboos, GHB 29-Mar-15 6:34am    
Now there is one thing about a form which you may have overlooked - and it's a primary attribute of using forms:

Data in a form is transmitted to the server (and later fed back to appropriate page) based upon the NAME attribute. As a general rule, you access elements on the page via their ID and send their content via NAME.

All items with a NAME will be sent when the form is submitted. No name - it's not there.

So - your elements, such as:
<td align="center"><div id="Responsible2"></div></td>
<td align="center"><div id="Progressid"></div></td>
</tr>
Will fail
Member 10738621 30-Mar-15 21:33pm    
Hi, thanks for your reply. Have added the div name as below:

<td align="center"><div name="Responsible2" id="Responsible2"></div></td>
<td align="center"><div name="Progressid" id="Progressid"></div></td>

But so far no record being saved and no email sent. Please advise n thanks a lot.
W Balboos, GHB 31-Mar-15 6:14am    
You really need to get a VERY basic tutorial on how HTML forms are used.

Try: http://www.w3schools.com/html/html_forms.asp

Actually - I'd suggest you try several of the tutorials as they're relevant to your learning how to do your work (e.g., php, javascript tutorials).

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900