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

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

$id = $_GET['id'];

if(isset($_POST['submit'])){
    $firstname = $_POST['firstname'];
    $lastname = $_POST['lastname'];
    $email = $_POST['email'];
    $phone_home = $_POST['phone_home'];
    $phone_cell = $_POST['phone_cell'];
    $address = $_POST['address'];
    $zipcode = $_POST['zipcode'];
    $city = $_POST['city'];
    $birthday = $_POST['birthday'];
    
    if($firstname == ""){
        ?>
            <div class="alert alert-error">
                You need to enter the firstname
            </div>
        <?php
    } else {
        $query = $mysqli->prepare("UPDATE `cal_contacts` SET `firstname`= ?,`lastname`= ?,`email`= ?,`phone_home`=? ,`phone_cell`= ?,`address`= ?,`zipcode`= ?,`city`= ?,`birthday`= ? WHERE `id` = ?");
        $query->bind_param(ssssssssss, $firstname,$lastname,$email,$phone_home,$phone_cell,$address,$zipcode,$city,$birthday,$id);
        $query->execute();
        $query->store_result();
        ?>
            <div class="alert alert-success">
                The data was saved successfully
            </div>
        <?php
    }
}

$query = $mysqli->prepare("SELECT
                                `cal_contacts`.`id`, 
                                `cal_contacts`.`firstname`, 
                                `cal_contacts`.`lastname`, 
                                `cal_contacts`.`email`, 
                                `cal_contacts`.`phone_home`, 
                                `cal_contacts`.`phone_cell`, 
                                `cal_contacts`.`address`, 
                                `cal_contacts`.`zipcode`, 
                                `cal_contacts`.`city`, 
                                `cal_contacts`.`birthday`, 
                                DATE_FORMAT(`cal_contacts`.`birthday`, '%d-%m-%Y') as `date_trans` 
                           FROM 
                                `cal_contacts` 
                           WHERE 
                                `id` = ?");
$query->bind_param(i, $id);
$query->bind_result($q_id, $q_firstname, $q_lastname, $q_email, $q_phone_home, $q_phone_cell, $q_address, $q_zipcode, $q_city, $q_birthday, $q_date_trans);
$query->execute();

while($row = $query->fetch()){
    $firstname = $q_firstname;
    $lastname = $q_lastname;
    $email = $q_email;
    $phone_home = $q_phone_home;
    $phone_cell = $q_phone_cell;
    $address = $q_address;
    $zipcode = $q_zipcode;
    $city = $q_city;
    $birthday = $q_birthday;
}
$query->store_result();


?>
<form class="form-horizontal" method="post" action="">
  <fieldset>
    <legend>Edit 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">Emailaddress</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-yyyy" 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