Best Web Host

phpMyEdit example

MySQL™ table editor

Filename: phpvs_sakila.staff.php


Additional Fields
 Email
 Store ID
 Active
 Username
 Password
 Last Update


 
Page: 1 of 1  Records: 2
Staff ID First Name Last Name Address ID Picture
Clear Sorted By: Staff ID ascending
View Change Copy Delete 1 Mike Hillyer 3 �PNG  IHDRyu�Z�e pHYs���o...
View Change Copy Delete 2 Jon Stephens 4  
Page: 1 of 1  Records: 2

Tables containing more than 'n' columns are configured to display the first 'n' columns and display links to toggle (add/remove) the remaining columns.

Users are advised to use phpMyAdmin to set an INDEX for columns which are often sorted/searched. Most web hosts provide phpMyAdmin in the website control panel.

Try Hostgator.com for excellent web hosting with cPanel, PHP, MySQL™ and many other features. cPanel PHP MySQL web hosting


phpMyEdit code created for the above table.

<?php

/*
 * Database: phpvs_sakila
 * Table: staff
 * Row count: 2
 * Column count: 11
 * Filename: phpvs_sakila.staff.php
 * Created Wed, 22 Feb 2012 18:59:57 -0700
 * Primary key: staff_id
 * Null fields: picture, email, password
 * Multi-key fields: address_id, store_id
 * All fields: staff_id, first_name, last_name, address_id, picture, email, store_id, active,
username, password, last_update
*/

$opts['tb'] = 'staff';

// phpMyEdit common variables + a few functions + UTF8 database connection

require_once('./resources/inc/config.php');

require_once(
'./resources/inc/header.php');

// Use phpMyAdmin to apply an INDEX to columns which are frequently sorted/searched.
// Prepending a minus sign (-) to a sort_field value causes DESCending sort order.

$opts['sort_field'] = array('staff_id');

$opts['key'] = 'staff_id';

$opts['key_type'] = 'int';

$opts['options'] = 'ACPVDFL';

// $opts['triggers']['insert']['after'] = 'resources/inc/triggers/view_rec_after_add.php';

if(empty($list_mode_status)){
   
// List mode
}elseif(isset($_REQUEST['PME_sys_operation']) || isset($_REQUEST['PME_sys_moreadd']) && isset($_REQUEST['PME_sys_morechange'])){
   
// 7 diffenent button clicks may occur
   // PME_sys_operation: Add, PME_op_Change, PME_op_Copy, PME_op_Delete, PME_op_View
   // PME_sys_moreadd: More
   // PME_sys_morechange: Apply
}


// Initialize toggle variables based on column number
$z5 get_cgi_var('z5');
$z6 get_cgi_var('z6');
$z7 get_cgi_var('z7');
$z8 get_cgi_var('z8');
$z9 get_cgi_var('z9');
$z10 get_cgi_var('z10');

// Toggle variables need to be persistent
$opts['cgi']['persist'] = array(
'z5' => $z5'z6' => $z6'z7' => $z7'z8' => $z8'z9' => $z9'z10' => $z10);

// Buffer the toggling links in order to facilitate their display
// above/below the form, or left/right the phpMyEdit form in TD tags
$my_link_buffer '';

if(
$list_mode_status){
   
$bqs ''// buffered query string (phpMyEdit system variables)
   
$ignore_keys = array(
      
'PME_sys_canceladd',
      
'PME_sys_cancelcopy',
      
'PME_sys_canceldelete',
      
'PME_sys_cancelview',
      
'PME_sys_cur_tab',
      
'PME_sys_moreadd',
      
'PME_sys_qfn',
      
'PME_sys_savechange'
   
);
   foreach(
$_REQUEST as $key => $val){
      if(
substr($key08) == 'PME_sys_' && !in_array($key$ignore_keys)){
         if(
is_array($val)){
            foreach(
$val as $k => $v){
               
$bqs .= '&'.$k.'='.$v;
            }
         }else{
            
$bqs .= '&'.$key.'='.$val;
         }
      }
   }
    
   
// calculate opposite values beginning with MySQL column #5
   
$tmp5 '&z5='.(empty($z5) ? 0);
   
$tmp6 '&z6='.(empty($z6) ? 0);
   
$tmp7 '&z7='.(empty($z7) ? 0);
   
$tmp8 '&z8='.(empty($z8) ? 0);
   
$tmp9 '&z9='.(empty($z9) ? 0);
   
$tmp10 '&z10='.(empty($z10) ? 0);

   
// template used to apply the above values
   
$tpl '&z5=%s&z6=%s&z7=%s&z8=%s&z9=%s&z10=%s';

    
// Note the progressive shift from one column to the next
   
$my_link_buffer .= "\n".'<p><hr>Additional Fields<hr>';
   
$my_link_buffer .= htmlLink(sprintf($tpl$tmp5$z6$z7$z8$z9$z10), 'Email'$z5);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$tmp6$z7$z8$z9$z10), 'Store ID'$z6);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$tmp7$z8$z9$z10), 'Active'$z7);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$z7$tmp8$z9$z10), 'Username'$z8);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$z7$z8$tmp9$z10), 'Password'$z9);
   
$my_link_buffer .= htmlLink(sprintf($tpl$z5$z6$z7$z8$z9$tmp10), 'Last Update'$z10);
   
$my_link_buffer .= "\n".'</p><br>';
}

// Buffered toggle links can be echo'ed in a container table TD left/right/below phpMyEdit form


echo "\n".'<table border="0" cellpadding="0" cellspacing="0">';

echo 
"\n".'<tr valign="top">';

if(!empty(
$my_link_buffer)){
   echo 
"\n".'<td style="white-space:nowrap;background-color:#f0f8ff;padding:10px;border:1px solid #cccccc">'."\n";
   echo 
$my_link_buffer;
   echo 
"\n".'</td>';
   echo 
"\n".'<td width="15">&nbsp;</td>'// spacer
}

echo 
"\n".'<td>'."\n"// container for phpMyEdit form

// Begin phpMyEdit field arrays

// column 0: `staff_id` int - tinyint(3) unsigned
// flags: auto_increment, not_null, primary_key, unsigned
// extra: auto_increment
$opts['fdd']['staff_id'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'input'      => 'R',
  
'name'       => 'Staff ID',
  
'options'    => 'VCDFL',
  
'select'     => 'T',
  
'size'       => 3,
  
'sort'       => true
);
// If the tab feature is implemented, the first column must have a tab
// $opts['fdd']['staff_id']['tab|ACP'] = 'Staff ID';


// column 1: `first_name` string - varchar(45)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['first_name'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 45 characters',
  
'input'      => '',
  
'maxlen'     => 45,
  
'name'       => 'First Name',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 45,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
$opts['fdd']['first_name']['js']['required'] = true;
$opts['fdd']['first_name']['js']['hint'] = 'An entry is required for First Name';


// column 2: `last_name` string - varchar(45)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['last_name'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 45 characters',
  
'input'      => '',
  
'maxlen'     => 45,
  
'name'       => 'Last Name',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 45,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
$opts['fdd']['last_name']['js']['required'] = true;
$opts['fdd']['last_name']['js']['hint'] = 'An entry is required for Last Name';


// column 3: `address_id` int - smallint(5) unsigned
// flags: multiple_key, not_null, unsigned
$opts['fdd']['address_id'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'help|ACP'   => 'Limit 5 digits',
  
'input'      => '',
  
'maxlen'     => 5,
  
'name'       => 'Address ID',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'size'       => 5,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
$opts['fdd']['address_id']['js']['required'] = true;
$opts['fdd']['address_id']['js']['regexp'] = '/^[0-9]*$/';
$opts['fdd']['address_id']['js']['hint'] = 'An entry is required for Address ID';


// column 4: `picture` blob
// flags: binary, blob
$opts['fdd']['picture'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 21,845 characters',
  
'input'      => '',
  
'maxlen'     => 21845,
  
'name'       => 'Picture',
  
'options'    => 'ACPVDFL',
  
'select'     => 'T',
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'strip_tags|FL' => true,
  
'textarea'   => array('rows' => 20'cols' => 80),
  
'trimlen|FL' => 50,
  
'sort'       => false
);
// $opts['fdd']['picture']['js']['required'] = true;
// $opts['fdd']['picture']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['picture']['js']['hint'] = 'An entry is required for Picture';


// column 5: `email` string - varchar(50)
// collation: utf8_general_ci
$opts['fdd']['email'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 50 characters',
  
'input'      => '',
  
'maxlen'     => 50,
  
'name'       => 'Email',
  
'options'    => $z5 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 50,
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
//  'URL'        => 'mailto:$value',
  
'sort'       => true
);
// $opts['fdd']['email']['js']['required'] = true;
// $opts['fdd']['email']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['email']['js']['hint'] = 'An entry is required for Email';


// column 6: `store_id` int - tinyint(3) unsigned
// flags: multiple_key, not_null, unsigned
$opts['fdd']['store_id'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'help|ACP'   => 'Limit 3 digits',
  
'input'      => '',
  
'maxlen'     => 3,
  
'name'       => 'Store ID',
  
'options'    => $z6 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 3,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['store_id']['js']['required'] = true;
// $opts['fdd']['store_id']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['store_id']['js']['hint'] = 'An entry is required for Store ID';


// column 7: `active` int - tinyint(1)
// flags: not_null
$opts['fdd']['active'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => 1,
  
'help|ACP'   => 'Limit 1 digits',
  
'input'      => '',
  
'maxlen'     => 1,
  
'name'       => 'Active',
  
'options'    => $z7 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 1,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['active']['js']['required'] = true;
// $opts['fdd']['active']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['active']['js']['hint'] = 'An entry is required for Active';


// column 8: `username` string - varchar(16)
// flags: not_null
// collation: utf8_general_ci
$opts['fdd']['username'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 16 characters',
  
'input'      => '',
  
'maxlen'     => 16,
  
'name'       => 'Username',
  
'options'    => $z8 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 16,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['username']['js']['required'] = true;
// $opts['fdd']['username']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['username']['js']['hint'] = 'An entry is required for Username';


// column 9: `password` string - varchar(40)
// flags: binary
// collation: utf8_bin
$opts['fdd']['password'] = array(
  
'default'    => '',
  
'help|ACP'   => 'Limit 40 characters',
  
'input'      => '',
  
'maxlen'     => 40,
  
'name'       => 'Password',
  
'options'    => $z9 'ACPVDFL' 'ACPVD',
  
'select'     => 'T',
  
'size'       => 40,
  
'sqlw'       => 'IF($val_qas = "", NULL, $val_qas)',
  
'sort'       => true
);
// $opts['fdd']['password']['js']['required'] = true;
// $opts['fdd']['password']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['password']['js']['hint'] = 'An entry is required for Password';


// column 10: `last_update` timestamp
// flags: binary, not_null, timestamp, unsigned, zerofill
// extra: on update CURRENT_TIMESTAMP
$opts['fdd']['last_update'] = array(
  
'css'        => array('postfix' => 'right-justify'),
  
'default'    => '',
  
'help|ACP'   => 'Timestamp',
  
'input'      => 'R',
  
'maxlen'     => 19,
  
'name'       => 'Last Update',
  
'options'    => $z10 'ACPVDFL' 'VD',
  
'select'     => 'N',
  
'size'       => 19,
  
'sqlw'       => 'TRIM("$val_as")',
  
'sort'       => true
);
// $opts['fdd']['last_update']['js']['required'] = true;
// $opts['fdd']['last_update']['js']['regexp'] = '/^[a-zA-Z]*$/'; // modify REGEXP to meet your needs
// $opts['fdd']['last_update']['js']['hint'] = 'An entry is required for Last Update';

require_once('./resources/inc/phpMyEdit.class.new.php');

new 
phpMyEdit($opts);

echo 
"\n".'</td>'// close the phpMyEdit form

echo "\n".'</tr>';

echo 
"\n".'</table>';

require_once(
'./resources/inc/footer.php');

?>


cPanel PHP MySQL web hosting

If you have pre-purchase questions, please call Doug Hockinson at (720) 334-7850 or send email to doug@hockinson.com.

Data used for this demo is a modified version of Sakila schema (converted to MyISAM type tables)

Related sites: php-form-generator.com | phpvs.com | hockinson.com | denvermetro.org

Content management system with built in photo galleries and phpMyEdit form generator: www.phpvs.com/cms2011/

Regarding the style sheet used by these scripts, un-comment some CSS code for body and wrapper in order to match the layout of the generator script.

In page modes Add, Change, and coPy, note the Help text displayed beside the fields. Several configurable options are available: character limit, link to Help popup, code supplied but commented out (no value), display "Entry Required", or MySQL Column Comment.