I'm making a custom plugin for a client and am having difficulty in making the forms and how it interacts with the DB. I've read plugin documentations form this site but I am having trouble completely understanding them as there are amendments and some incomplete documentation. I just want to update data in the database.
Using WP 2.8.4
here is my code:
add_action('admin_init', 'res_settings' );
//for reservation settings
$settingsQ = mysql_query('select * from '.$wpdb->prefix.'res_settings order by uid asc limit 1') or die(mysql_error());
//$setEmail = $wpdb->get_row($settingsQ);
$setEmail = mysql_fetch_array($settingsQ);
register_setting('res_options', 'res_email', $setEmail['email']);
register_setting('res_options', 'res_uid', $setEmail['uid']);
add_submenu_page('options-general.php', 'Reservation Settings', 'Reservation Settings', 7, __FILE__, 'reservation_settings');
mysql_query('update '.$wpdb->prefix.'res_settings set email="'.$_POST['res_email'].'" where uid="'.$_POST['res_uid'].'"');
$conf_update = '<th scope="row">E-mail list updated.</th>';
$out = '
<form method="post" action="'.$_SERVER['REQUEST_URI'].'">
<th scope="row">E-mail: Set the E-mail or E-mails where all reservation E-mails will be sent (list of emails MUST be separated by commas).</th>
<td><input type="text" name="res_email" size="100" value="'.get_option('res_email').'" /></td>
<input type="submit" class="button-primary" value="Update" />
I am registering settings and its data comes from DB. the settings_fields function does not seem to echo out the hidden fields and i am not sure if the get_option function does not seem to work either. on form submission $_POST does not seem to work as well. I know that the html is being outputted in a function, I think this is the main problem, moreover, I am not sure if I am creating the form correctly.
thanks in advance