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

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

//when posted
if(isset($_POST['submit'])){
    $role = $_POST['role'];
    $username = $database->escape($_POST['username']);
    $email = $database->escape($_POST['email']);
    $password = $database->escape($_POST['password']);
    $password = md5($password);
        
    if($_POST['mailinglist'] == 'on'){
        $mailinglist = 1;
    } else {
        $mailinglist = 0;
    }
    
    $q = $database->query("INSERT INTO `cal_users` (`role`,`username`,`password`,`email`,`mailinglist`) VALUES ('$role','$username','$password','$email','$mailinglist')");
    
    //if query is done
    if($q){
        ?>
        <div class="alert alert-success">
            The data is saved successfully
        </div>
        <?php
    } else {
        ?>
        <div class="alert alert-error">
            There was an error during the saving, please try again
        </div>
        <?php
    }
}

?>
<form class="form-horizontal" method="post" action="">
  <fieldset>
    <legend>Add user</legend>
    <div class="control-group">
      <label class="control-label" for="role">Role</label>
      <div class="controls">
        <select class="span3" name="role">
            <option value="1" >User</option>
            <option value="2" >Administrator</option>
        </select>
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" for="username">Username</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="username" name="username" value="">
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" for="password">Password</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="password" name="password">
      </div>
    </div>
    <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">
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" for="mailinglist">Mailinglist</label>
      <div class="controls">
        <input type="checkbox" name="mailinglist" />
      </div>
    </div>
    <div class="control-group">
      <div class="controls">
            <button type="submit" class="btn btn-primary" name="submit">Save</button>
      </div>
    </div>
  </fieldset>
</form>
<?php

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