mysql - Adding in a PHP email to a file that has info sent with an AJAX call killing code -


i created code updates user's group level(permission level). send selected id , group level via ajax php file called user_update_group. updating user's group # worked before tried add php email in same file. i'm doing because getting user's info database, thought best approach.

however, when adding in email breaks code. there in php file killing or can not way? trying select data in users table id brought on , send email out them using same button other query used. php email second part in php file added in here. added in of code show trying do.

<?php $con2 = mysqli_connect("localhost", "root", "", "db"); $run2 = mysqli_query($con2,"select * user_requests order id desc"); $runusers2 = mysqli_query($con2,"select * users order id desc"); $numrows2 = mysqli_num_rows($run2);      if( $numrows2 ) {         while($row2 = mysqli_fetch_assoc($run2)){             if($row2['status'] == "approved"){             //var_dump ($row2);                  $approved_id        = $row2['user_id'];                 $approved_firstname = $row2['firstname'];                 $approved_lastname  = $row2['lastname'];                 $approved_username  = $row2['username'];      if ($approved_firstname == true) {         echo "name - ". $approved_firstname . " " . $approved_lastname . "  </br>" .                  "username - ". $approved_username . "</br></br>" ?> <div class="change_group_button">       <a class="change_group" href="javascript:void(0)">change user permission</a> </div><br> <div id="light" class="change_group_popup">     <a class="close" href="javascript:void(0)">close</a>  <div class="group_success" style="color: red;"></div><br>     <form id="update_group" action="" method="post" accept-charset="utf-8">        <div class="field">         <label for="group">group</label>         <input type="hidden" value="<?php echo $approved_id; ?>" id="approved_id" name="id" />         <select id='group_id' name='group' required>             <option value=''><?php echo htmlentities($group); ?></option>             <option value="1">bench</option>             <option value="2">spectator</option>             <option value="3">team member</option>             <option value="4">commissioner</option>         </select>     </div>     <input type="submit" value="submit" name="group">     </form> 

ajax call

$(document).ready(function () {      $('#update_group').on('submit', function (event) {     event.preventdefault();         $.ajax({             url: 'user_group_update.php',             type: 'post',             data: {             id: $("#approved_id").val(), //id            // update_group: $("#group_id").val() //group level           update_group: $(this).find( "#group_id option:selected" ).val()         },             success: function (data) {                 //do data got returned                 $(".group_success").fadein();                 $(".group_success").show();                 $('.group_success').html('user permission level changed!');                 $('.group_success').delay(5000).fadeout(400);                // alert(data);             },              error: function(jqxhr, textstatus,errorthrown )             {               // alert on http error                alert( textstatus +  errorthrown );             }         });         return false;     }); }); 

user_group_update php file.

$approved_id = $_post['id']; $change_group = $_post['update_group'];  $con = mysqli_connect("localhost","root","","db");     /* check connection */     if (mysqli_connect_errno()) {         printf("connect failed: %s\n", mysqli_connect_error());         exit();     }     $stmt = $con->prepare("update users set `group`=? id=?");     if ( !$stmt || $con->error ) {      // check errors prepare         die('user group update prepare() failed: ' . htmlspecialchars($con->error));     }     if(!$stmt->bind_param('ii', $change_group, $approved_id)) {     // check errors binding parameters         die('user group update bind_param() failed: ' . htmlspecialchars($stmt->error));     }     if(!$stmt->execute()) {         die('user group update execute() failed: ' . htmlspecialchars($stmt->error));     }      //-------email test--------------      $email_stmt = $con->prepare("select * users id=?");     if ( !$email_stmt || $con->error ) {      // check errors prepare         die('user email prepare() failed: ' . htmlspecialchars($con->error));     }/*     if(!$email_stmt->bind_param('ii', $change_group, $approved_id)) {     // check errors binding parameters         die('user email bind_param() failed: ' . htmlspecialchars($stmt->error));     }     if(!$email_stmt->execute()) {         die('user email execute() failed: ' . htmlspecialchars($stmt->error));*/         /*$pending_id = $_post['id'];         $group_firstname = $_post['firstname'];             $group_lastname = $_post['lastname'];             $group_username = $_post['username'];             $group_email = $_post['email'];             $group_email = $_post['group'];              $to = $group_email;             $subject = 'there new user request join sunday funday league';             $message = '             <html>             <head>                 <title>new sfl user request</title>             </head>             <body>                 <p>hi '.$group_firstname.',</p><br>                 <p>your sunday funday league account has been accepted. have been added group. sign in, click link                 http://sundayfundayleague.com . </p><br>                 <p>thank you,</p>                 <p>administration</p>             </body>             </html>             ';              $from = "user-requests@sundayfundayleague.com";             $bcc = "user-requests-confirm@sundayfundayleague.com";              // send html mail, content-type header must set             $headers  = 'mime-version: 1.0' . "\r\n";             $headers .= 'content-type: text/html; charset=iso-8859-1' . "\r\n";              // additional headers             $headers .= 'to: ' .$to. "\r\n";             $headers .= 'from: ' .$from. "\r\n";             $headers .= 'bcc: '.$bcc. "\r\n";              // send email             mail($to,$subject,$message,$headers);     }*/ 

update code user_update_group file

$approved_id = $_post['id']; //test - delete if doesn't work $approved_firstname = $_post['firstname']; $approved_lastname = $_post['lastname']; $approved_username = $_post['username']; $approved_email = $_post['email']; $change_group = $_post['update_group'];   $con = mysqli_connect("localhost","root","","db");     /* check connection */     if (mysqli_connect_errno()) {         printf("connect failed: %s\n", mysqli_connect_error());         exit();     }     $stmt = $con->prepare("update users,user_requests set users.group=?, user_requests.group=? users.id=? , user_requests.user_id=?");     if ( !$stmt || $con->error ) {      // check errors prepare         die('user group update prepare() failed: ' . htmlspecialchars($con->error));     }     if(!$stmt->bind_param('iiii', $change_group, $change_group, $approved_id, $approved_id)) {     // check errors binding parameters         die('user group update bind_param() failed: ' . htmlspecialchars($stmt->error));     }     if(!$stmt->execute()) {         die('user group update execute() failed: ' . htmlspecialchars($stmt->error));     }      //test     $email_stmt = $con->prepare("select * users id=?");     if ( !$email_stmt || $con->error ) {      // check errors prepare         die('user email prepare() failed: ' . htmlspecialchars($con->error));     }     /*if(!$email_stmt->bind_param('ii', $change_group, $approved_id)) {     // check errors binding parameters         die('user email bind_param() failed: ' . htmlspecialchars($stmt->error));     }     if(!$email_stmt->execute()) {         die('user email execute() failed: ' . htmlspecialchars($stmt->error));*/              $to = $approved_email;             $subject = 'there new user request join t';             $message = '             <html>             <head>                 <title>new user request</title>             </head>             <body>                 <p>hi '.$approved_firstname.',</p><br>                 <p>your  account has been accepted. have been added group. sign in, click link                 http://example.com . </p><br>                 <p>thank you,</p>                 <p>administration</p>             </body>             </html>             ';              $from = "user-requests@example.com";             $bcc = "user-requests-confirm@example.com";              // send html mail, content-type header must set             $headers  = 'mime-version: 1.0' . "\r\n";             $headers .= 'content-type: text/html; charset=iso-8859-1' . "\r\n";              // additional headers             $headers .= 'to: ' .$to;//. "\r\n";             $headers .= 'from: ' .$from;//. "\r\n";             $headers .= 'bcc: '.$bcc;//. "\r\n";              // send email             mail($to,$subject,$message,$headers); 

_post auto generated browser on submit of form. if want pass data through post have use form submit fields. these fields can hidden:

<input type=hidden name="lastname" value="{some_last_name}"/> 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -