DBDelta is extremely picky— to the point of being maddening sometimes. From the Codex:
- You must put each field on its own line in your SQL statement.
- You must have two spaces between the words PRIMARY KEY and the definition of your primary key.
- You must use the key word KEY rather than its synonym INDEX and you must include at least one KEY.
- You must not use any apostrophes or backticks around field names.
It looks to me like you have violated at least two of those rules. You should have something more like this:
$sql="
CREATE TABLE $my_table (
id int(20) not null auto_increment,
name varchar(40) not null,
password varchar(20) notnull,
PRIMARY KEY id
);";
I removed IF NOT EXISTS
. dbdelta
will update the table if the table needs updating and leave it alone otherwise, hence the name “database delta”. In mathematics “delta”– the Greek letter– means something like “change” or “difference”.
I do not promise that that code will work since, as I said, dbdelta
is very picky. I am sure that it is the format of your SQL statement that is the problem and that should get you moving in the right direction.