Location: PHPKode > scripts > PHP Address book > php-address-book_v_1.02_eng/settings.php
<?php 
include_once 'includes/header.inc.php'; 

if(!$session->getRole() == 1 or !$session->getRole() == 2){
    header("location: login.php");
}

$userid = $_SESSION['userid'];

//submit the form
if(isset($_POST['submit'])){
    $email = $_POST['email'];
    $mailinglist = $_POST['mailinglist'];
    
    if($mailinglist == "on"){
        $mailinglist = 1;
    } else {
        $mailinglist = 0;
    }
    
    if($email != ""){
        $query = $mysqli->prepare("  UPDATE 
                            `cal_users` 
                            SET 
                            `email`= ?,
                            `mailinglist`= ? 
                            WHERE 
                            `id` = ?
                        ");
        
        $query->bind_param(ssi, $email, $mailinglist, $userid);
        $query->execute();
        $query->store_result();
        ?>
            <div class="alert alert-success">
                The data was saved successfully
            </div>
        <?php
    } else {        
        ?>
            <div class="alert alert-error">
                You must enter an e-mail address
            </div>
        <?php
    }
}

//get user info from database
$query = $mysqli->prepare(" SELECT 
                            `cal_users`.`id`,
                            `cal_users`.`role`,
                            `cal_users`.`username`,
                            `cal_users`.`email`,
                            `cal_users`.`mailinglist`
                            FROM 
                            `cal_users` 
                            WHERE 
                            `id` = ?
                          ");
$query->bind_param(i, $userid);
$query->bind_result($q_id, $q_role, $q_username, $q_email, $q_mailinglist);
$query->execute();

while($query->fetch()){
    $email = $q_email;
    $mailinglist = $q_mailinglist;
}
$query->store_result();

?>
<form class="form-horizontal" method="post" action="">
  <fieldset>
    <legend>My Settings</legend>
    <div class="control-group">
      <label class="control-label" for="email">E-mail</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="email" name="email" value="<?php echo $email; ?>">
      </div>
    </div>
    <div class="control-group">
        <label class="control-label" for="mailinglist">Mailinglist</label>
        <div class="controls">
            <label class="checkbox">
            <input type="checkbox" id="mailinglist" name="mailinglist" <?php if($mailinglist == 1){ echo "checked"; } ?> >
            </label>
        </div>
    </div>
    <div class="form-actions">
        <button type="submit" class="btn btn-primary" name="submit">Save</button>
        <button class="btn">Cancel</button>
    </div>
  </fieldset>
</form>

<?php include_once 'includes/footer.inc.php'; ?>
Return current item: PHP Address book