Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Assign values for saving to the db
- $data = array(
- 'table_of_contents' => $_POST['table_of_contents'],
- 'length' => $_POST['length']
- );
- # Check for fields that may not be set
- if ( isset($_POST['lossless_copy']) )
- {
- $data = array(
- 'lossless_copy' => $_POST['lossless_copy']
- );
- }
- // etc.
- // this is an array of default values for the fields that could be in the POST
- $defaultValues = array(
- 'table_of_contents' => '',
- 'length' => 25,
- 'lossless_copy' => false,
- );
- $data = array_merge($defaultValues, $_POST);
- // $data is now the post with all the keys set
- $optional = array('lossless_copy', 'bossless_floppy', 'foo');
- foreach ($optional as $field) {
- if (isset($_POST[$field])) {
- $data[$field] = $_POST[$field];
- }
- }
- foreach ($_POST as $key => $value) {
- $data[$key] = $value;
- }
- $fields = array();
- $table = 'Current_Table';
- // we are not using mysql_list_fields() as it is deprecated
- $query = "SHOW COLUMNS from {$table}";
- $result = mysql_query($query);
- while ($get = mysql_fetch_object($result) ) {
- $fields[] = $get->Field;
- }
- foreach($fields as $field) {
- if (isset($_POST[$field]) ) {
- $data[$field] = $_POST[$field];
- }
- }
- $formfields = $_POST;
- $data = array();
- foreach(array_keys($formfields) as $fieldname){
- $data[$fieldname] = $_POST[$fieldname];
- }
Add Comment
Please, Sign In to add comment