0

I have the code to update the user in the application that updates the user in the database. My problem is that when I click on the button aktivan = active (when the user is registered there status neaktivan = inactive, so I'm as administrators have to approve) to automatically send e-mail to that he was active?

<div class="control-group <?php echo !empty($status_racunaError)?'error':'';?>">
        <label class="control-label">Status računa:</label>
        <div class="controls">
            <input name="status_racuna" id="status_racuna" type="text" placeholder="Status računa" value="<?php echo !empty($status_racuna)?$status_racuna:'';?>"> &nbsp 
            <button name="btn-upload" type="submit" id="btn-upload" class="btn btn-success" onclick="aktivan()"><i class="glyphicon glyphicon-send"></i> aktivan</button> 
             &nbsp <button type="button" onClick="neaktivan()" class="btn btn-danger">neaktivan</button>
            <?php if (!empty($emailError)): ?>
                <span class="help-inline"><?php echo $status_racunaError;?></span>
            <?php endif;?>
        </div>
      </div>

      <div class="form-actions">
          <button type="submit" class="btn btn-success">Ažuriraj</button>
          <a class="btn" href="admin_zona.php">Nazad</a>
        </div>
    </form>
</div>

The screenshot is below this looks like..

I wrote this code for sending e-mail, but I do not know whether to call it from a new file or can call within the same (update.php)

echo "<div class=\"poruka_korisnik\"><p>Email je poslan na korisnikovu adresu. <i>$_POST[email]</i>. Molimo Vas da provjerite svoj e-mail.</p></div>";
                        $to = $_POST['email'];
                        $subject = "OPG Burza: obavijest o registraciji";
                        $message = "Dobrodošli!\r\r Hvala Vam što ste se registrirali na OPG Burzu. Vaš zahtjev za registracijom je odobren. Možete pristupiti našoj stranici na poveznici www.opg-burza.com.";
                        $headers  = 'MIME-Version: 1.0' . "\r\n";
                        $headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
                        $headers .= 'From: OPG Burza team <noreply@opg-burza.com>' . "\r\n";
                        mail($to, $subject, $message, $headers);
                        }

I tried in every way, the new script, but something did not set well. Any ideas or how to accurately define a script that sends e-mail just this particular user and can be from the same file update.php send the mail?

ekad
  • 14,436
  • 26
  • 44
  • 46
jedan_lik
  • 3
  • 2

1 Answers1

0

What is behind your

neaktivan() aktivan()

function?

Js, background php code, etc

Try this before the form to handle the post:

 <?php 
if (isset($_POST['status_racuna']) && isset($_POST['user_id'])) {
    #do some validation here
    $status_racuna = $_POST['status_racuna'];
    $user_id = $_POST['user_id'];
    $sql="UPDATE users SET activ= '{$status_racuna}' where id={$user_id}";
    $updated = $db->query($sql);
    if ($updated) {
        #display success message
        # send mail
    } else {
        # display the error message
    }
}
?>

I cannot see you opened the form or not. and add hidden input with name user_id.

Bela_b
  • 121
  • 5
  • JavaScript function. aktivan=active neaktivan=inactive – jedan_lik Sep 25 '16 at 07:33