Using get_current_user_id() Inserted into my WPDB table.
-
So I would like my plugin to insert the current user’s ID into my table, “wp_ml_char”.
The problem is, it’s failing to actually insert it; nothing happens and no errors are displayed. This form is only asking me to put in a name, but it also has a “hidden” input type which grabs whatever user ID is currently present. I can’t pinpoint where the cause is exactly, but it might be the “hidden” input line I made. Thanks in advance to anyone that can help!// Character creation form. Grab the current user's ID. require_once('/home/mythlarp/public_html/wp-includes/user.php'); $wpid = get_current_user_id(); function html_form_code() { echo '<form action="index.php" method="post">'; echo '<input type="hidden" name="wp_id" value="<?php echo $wpid; ?>" />'; echo '<p>'; echo 'Character Name (required) <br />'; echo '<input type="text" name="ml_char_name" pattern="[a-zA-Z]+" value=""' . ( isset( $_POST["ml_char_name"] ) ? esc_attr( $_POST["ml_char_name"] ) : '' ) . '" size="40" />'; echo '</p>'; echo '<p><input type="submit" name="cf-submitted" value="Send"/></p>'; echo '</form>'; } // Insert form data. $wpdb->insert('$table_name', array( 'ml_char_name' => $_POST['ml_char_name'], 'wp_id' => $_POST['wp_id'], ));
- The topic ‘Using get_current_user_id() Inserted into my WPDB table.’ is closed to new replies.