How to create a table [closed]

Here you go Javier, this should work. I included comments within the code to try and show you where things needed to change and added a few things you were missing. I’ll explain more below.

<?php
/* Should really come up with something more unique and related to your plugin */
function yourplugin_dbcreation() {
    global $wpdb;
    $charset_collate        = $wpdb->get_charset_collate();
    /* Please come up with something more descriptive or unique for this */
    $table_name             = $wpdb->prefix . 'form';
    require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );
    /* Since you're not only running this on activation, let's do a quick check to see if it exists before we move further */
    if( $wpdb->get_var( "SHOW TABLES LIKE '$table_name'" ) != $table_name ) {
        /* dbDelta() has strict rules about how to format the SQL statement, field types must be lower case, do not put headings in backticks, etc. */
        $sql = "CREATE TABLE $table_name (
            id int(11) NOT NULL AUTO_INCREMENT,
            name varchar(255) NOT NULL,
            email varchar(255) NOT NULL,
            UNIQUE KEY id  (id),
            PRIMARY KEY  (id)
        );";
        dbDelta( $sql );
        /* You add this next line in case you ever want to update the table structure, so you'd run a version check to determine whether or not to execute the change.  If your new version matches this option, you do nothing, if the option is lower than your new table version, you'd run the code for the update. */
        add_option( 'form_db', '1.0' );
    }
}
/* you could use this, but better to run it on activation with register_activation_hook( 'plugin_path', 'your_function' );*/
add_action( 'init', 'yourplugin_dbcreation' );
?>

So a couple of things, as Jacob Peattie points out in his comment, there are details you needed to address and lines of code you needed to include that are explained in the link he provided.

dbDelta() is a very specific and finicky thing – so you really have to make sure you observe the rules. It’s not lenient at all and if you don’t follow it’s strict instructions it just won’t execute.

You were also missing a few key lines, like dbDelta() itself – without that, WP doesn’t know what to do with your code.

Personally I prefer creating the table on plugin activation, but you didn’t provide any plugin information and you have to get the path absolutely correct or it won’t work. (Jacob’s link actually shows you how to do it.)

Final thing, you’ve got to be a bit more unique and descriptive when naming functions and tables. Even if you don’t personally need them to be descriptive, at least ensure you put some effort into them being unique so that they’re not generic like creation or form. When you leave them generic like that, all you’re doing is inviting conflicts when you install something by another developer who also didn’t make their code unique. Then you suddenly have two functions named creation and neither one works. If you consider the amount of tutorials and snippets out there that people are using, it’s not at all uncommon.

Hope this all helps. 🙂