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

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

if(isset($_POST['submit'])){
    $firstname = $database->escape($_POST['firstname']);
    $lastname = $database->escape($_POST['lastname']);
    $email = $database->escape($_POST['email']);
    $phone_home = $database->escape($_POST['phone_home']);
    $phone_cell = $database->escape($_POST['phone_cell']);
    $address = $database->escape($_POST['address']);
    $zipcode = $database->escape($_POST['zipcode']);
    $city = $database->escape($_POST['city']);
    $birthday = $database->escape($_POST['birthday']);
    
    if($firstname == ""){
        ?>
            <div class="alert alert-error">
                You need to enter the firstname
            </div>
        <?php
    } else {
        $database->query("INSERT INTO `cal_contacts` (`firstname`,`lastname`,`email`,`phone_home`,`phone_cell`,`address`,`zipcode`,`city`,`birthday`) VALUES 
                                                      ('$firstname','$lastname','$email','$phone_home','$phone_cell','$address','$zipcode','$city', STR_TO_DATE('$birthday','%d-%m-%Y'))");
        
        $firstname = "";
        $lastname = "";
        $email = "";
        $phone_home = "";
        $phone_cell = "";
        $address = "";
        $zipcode = "";
        $city = "";
        $birthday = "";
        ?>
            <div class="alert alert-success">
                The data is saved successfully
            </div>
        <?php
    }
}

?>
<form class="form-horizontal" method="post" action="">
  <fieldset>
    <legend>Add contact</legend>
    <div class="control-group">
      <label class="control-label" for="firstname">Firstname</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="firstname" name="firstname" value="<?php echo $firstname; ?>">
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" for="lastname">Lastname</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="lastname" name="lastname" value="<?php echo $lastname; ?>">
      </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"  value="<?php echo $email; ?>">
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" for="phone_home">Phone (home)</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="phone_home" name="phone_home"  value="<?php echo $phone_home; ?>">
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" for="phone_cell">Phone (cell)</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="phone_cell" name="phone_cell"  value="<?php echo $phone_cell; ?>">
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" for="address">Street</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="address" name="address"  value="<?php echo $address; ?>">
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" for="zipcode">Zipcode</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="zipcode" name="zipcode" value="<?php echo $zipcode; ?>">
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" for="city">City</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="city" name="city" value="<?php echo $city; ?>">
      </div>
    </div>
    <div class="control-group">
      <label class="control-label" for="datepicker">Date of birth</label>
      <div class="controls">
        <input type="text" class="input-xlarge" id="datepicker" placeholder="dd-mm-jjjj" name="birthday" value="<?php echo $birthday; ?>"> 
      </div>
    </div>
    <div class="control-group">
      <div class="controls">
            <button type="submit" class="btn btn-primary" name="submit">Save changes</button>
      </div>
    </div>
  </fieldset>
</form>
<?php include_once 'includes/footer.inc.php'; ?>
Return current item: PHP Address book