PHP Classes

File: fwphp/glomodul/z_examples/MVC_FW/03xuding_users2017/update.php

Recommend this page to a friend!
  Classes of Slavko Srakocic   B12 PHP FW   fwphp/glomodul/z_examples/MVC_FW/03xuding_users2017/update.php   Download  
File: fwphp/glomodul/z_examples/MVC_FW/03xuding_users2017/update.php
Role: Example script
Content type: text/plain
Description: Example script
Class: B12 PHP FW
Manage database records with a PDO CRUD interface
Author: By
Last change: Update of fwphp/glomodul/z_examples/MVC_FW/03xuding_users2017/update.php
Date: 1 year ago
Size: 4,748 bytes


Class file image Download
//defined('ROOTDIR') or define('ROOTDIR',$_SERVER['DOCUMENT_ROOT']);
$id = null;
    if ( !empty(
$_GET['id'])) {
$id = $_REQUEST['id'];
    if (
null==$id ) {
header("Location: index.php");
    if ( !empty(
$_POST)) {
// keep track validation errors
$nameError = null;
$emailError = null;
$mobileError = null;
// keep track post values
$name = $_POST['user_name'];
$email = $_POST['user_email'];
$mobile = $_POST['user_telefon'];
// validate input
$valid = true;
        if (empty(
$name)) {
$nameError = 'Please enter Name';
$valid = false;
        if (empty(
$email)) {
$emailError = 'Please enter Email Address';
$valid = false;
        } else if ( !
filter_var($email,FILTER_VALIDATE_EMAIL) ) {
$emailError = 'Please enter a valid Email Address';
$valid = false;
        if (empty(
$mobile)) {
$mobileError = 'Please enter Mobile Number';
$valid = false;
// update data
if ($valid) {
$pdo = Database::connect();
$sql = "UPDATE users set user_name = ?, user_email = ?
                    , user_telefon =? WHERE user_id = ?"
$q = $pdo->prepare($sql);
header("Location: index.php");
    } else {
$pdo = Database::connect();
$sql = "SELECT * FROM users where user_id = ?";
$q = $pdo->prepare($sql);
$data = $q->fetch(PDO::FETCH_ASSOC);
$name = $data['user_name'];
$email = $data['user_email'];
$mobile = $data['user_telefon'];

<!DOCTYPE html>
<html lang="en">
    <meta charset="utf-8">
    <!--link href="css/bootstrap.min.css" rel="stylesheet"-->
      <link href="<?= CSSURL.'/bootstrap.min.css' ?>"
            rel="stylesheet" type="text/css">
    <!--script src="js/bootstrap.min.js"></script-->
    <script src="<?= JSURL.'/bootstrap.min.js' ?>"></script>
    <div class="container">
      <div class="span10 offset1">
          <div class="row">
              <h3>Update a Customer</h3>
          <form class="form-horizontal" method="post"
                action="update.php?id=<?php echo $id?>">
            <div class="control-group <?php echo !empty($nameError)?'error':'';?>">
              <label class="control-label">Name</label>
              <div class="controls">
                  <input name="user_name" type="text" placeholder="Name" value="<?php echo !empty($name)?$name:'';?>">
                  <?php if (!empty($nameError)): ?>
<span class="help-inline"><?php echo $nameError;?></span>
                  <?php endif; ?>
            <div class="control-group <?php echo !empty($emailError)?'error':'';?>">
              <label class="control-label">Email Address</label>
              <div class="controls">
                  <input name="user_email" type="text" placeholder="Email Address" value="<?php echo !empty($email)?$email:'';?>">
                  <?php if (!empty($emailError)): ?>
<span class="help-inline"><?php echo $emailError;?></span>
                  <?php endif;?>
            <div class="control-group <?php echo !empty($mobileError)?'error':'';?>">
              <label class="control-label">Mobile Number</label>
              <div class="controls">
                  <input name="user_telefon" type="text" placeholder="Mobile Number" value="<?php echo !empty($mobile)?$mobile:'';?>">
                  <?php if (!empty($mobileError)): ?>
<span class="help-inline"><?php echo $mobileError;?></span>
                  <?php endif;?>
            <div class="form-actions">
                <button type="submit" class="btn btn-success">Update</button>
                <a class="btn" href="index.php">Back</a>
    </div> <!-- /container -->