I am sending value from ajax to php to manipulate database values. Also i am trying to run mail() after posting value. But only manipulation in the database is happening. Please help. This is my form: profile.php
<form method="post" name="form">
<table class="table v-middle display" id="table">
<thead>
<tr>
<th >Sl.no</th>
<th >Owner Name</th>
<th >Contact Number</th>
<th>Email </th>
<th data-title="Action">Action</th>
</tr>
</thead>
<tbody id="responsive-table-body">
<?php
$owner=mysql_query("select id,tmp_id,name,phone,email,activate from pgowner where active='1'");
if(mysql_num_rows($owner)){
$i=0;
while($owner1=mysql_fetch_array($owner)){
$id=$owner1['tmp_id'];
?>
<tr>
<td><span class="label label-default"><?php echo ++$i; ?></span></td>
<td>
<a href='viewprofile?id=<?php echo $id; ?>' target='_blank' style='color:blue;text-decoration:underline;'><?php echo $owner1['name']; ?></a>
<input type="hidden" name="ownerid" value="<?php echo $owner1['tmp_id']; ?>" id="ownerid" />
</td>
<td class="phone">
<?php echo $owner1['phone'];
?>
</td>
<td class="email">
<?php echo $owner1['email'];
?>
</td>
<td>
<div class="onoffswitch">
<input type="checkbox" name="activate[]" class="onoffswitch-checkbox activate" id="activate<?php echo $id; ?>"
<?php
$query3=mysql_query("select tmp_id,activate from pgowner where tmp_id='$id'");
$query4=mysql_fetch_array($query3);
if($query4['activate']=="1")
{
echo "checked";
}
?>>
<label class="onoffswitch-label" for="activate<?php echo $id; ?>">
<div class="onoffswitch-inner"></div>
<div class="onoffswitch-switch"></div>
</label>
</div>
</td>
</tr>
<?php } }
?>
</tbody>
</table>
</form>
This is my ajax code:
<script type="text/javascript">
$(document).ready(function() {
$('.activate').click(function() {
var ownerid = $(this).closest('tr').find('input[name="ownerid"]').val();
var email =$(this).closest('tr').find('td.email').text().replace(/\s+/g, " ");
var phone =$(this).closest('tr').find('td.phone').text().replace(/\s+/g, " ");
var a = this.checked ? 1 : 0;
alert(email);
alert( phone);
$.ajax({
type: "POST",
url: "profileactivation",
data: {
value: a,
ownerid: ownerid,
email : email,
phone : phone
},
success: function(html) {
alert('Successfully Done');
},
error : function(html){
alert("Error occured !!");
}
});
});
});
</script>
My code to update db and send mail:
<?php
if($_POST){
if(mysql_real_escape_string($_POST['value']=='1')){
$ownerid=mysql_real_escape_string($_POST['ownerid']);
$email=mysql_real_escape_string($_POST['email']);
$phone=mysql_real_escape_string($_POST['phone']);
$activate=mysql_query("update pgowner set activate='1' where tmp_id='$ownerid'");
$to=$email;
$subject = "Profile Activation Mail";
$message = "
<html>
<head>
<p>Activated</p>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "X-Priority: 1 (Highest)\n";
$headers .= "X-MSMail-Priority: High\n";
$headers .= "Importance: High\n";
// More headers
$headers .= 'From: <info@example.com>' . "\r\n";
mail($to,$subject,$message,$headers);
}
}
?>