Everything seems to be working fine until i get to the insert. I am trying to get this to work on a plugin i am creating. This is for the plugin options section.
Here is the form code:
<form id="mcp_form_submit" action="<?php echo admin_url(); ?>/admin-ajax.php">
<?php
?>
<?php $spages = get_select_pages(); ?>
<?php //do_settings_sections( 'mcp-settings-group' ); ?>
<table class="form-table">
<tr valign="top">
<th scope="row">Page Title</th>
<td>
<select id="select_dropdown" name="page_title">
<?php foreach ($spages as $spage) {?>
<?php //check to see if it hasnt already been edited. make function to check ?>
<option value="<?php echo $spage->ID; ?>"><?php echo $spage->post_name; ?></option>
<?php } ?>
</select>
</td>
</tr>
<tr valign="top">
<th scope="row">Meta Description</th></td>
<td><textarea id='metadesc' placeholder="(Max 160 Chars.)" rows="4" cols="50" name="meta_description" value=""></textarea>
</tr>
</table>
<?php submit_button(); ?>
And here is the form submission code:
function mcp_insert_custom_table_do($post_id, $desc)
{
global $wpdb;
//check to see if it exists
$rw = mcp_get_by_id($post_id);
if ($rw == NULL) {
$res = $wpdb->insert(
'wp_meta_changer',
array(
'post_id' => $post_id,
'description' => $desc
),
array(
'%d',
'%s'
)
);
return $res;
}
else
{
//Update it
$res = $wpdb->update(
'wp_meta_changer',
array(
'description' => $desc
),
array( 'post_id' => $post_id ),
array(
'%s'
),
array( '%d' )
);
return $res;
}
}
It works by AJAX, and that part is working. It’s only the actual $wpdb->insert that is having a problem.