Can't able to create mysqli table?

This is the code

$mysqli = new mysqli( $db_host, $db_user, $db_pass, $db_name);
// instead of mysqli_connect, use object mysqli

if ($mysqli ->connect_errno) {
  printf("Connect Failed: %s\n", $mysqli->connect_error);

$object_table = "CREATE TABLE IF NOT EXISTS test (
        user_id bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
        post_title text NOT NULL,
        post_content text NOT NULL,
        post_name VARCHAR(255) NOT NULL,
        post_date datetime NOT NULL,

if ($mysqli->query($object_table) === True){
    printf("Table object inserted successfully.\n");
} else {

I am getting the output - FAILED, where I am doing wrong?

user_id is not equal to ID so PRIMARY KEY(ID) fails?

(Don’t feel alone, I often look at something for so long I don’'t see it until I take a break and get back to it.)


Thanks, actually that time I am in hurry, my mom keep calling me, so I didn’t see the primary key :tongue:

For future debugging, echo out the actual error the db returns, instead of a “failed” message

Yeah I know, as I said I am in a hurry last time, so I wrote the one-word sentence to get the immediate result lol.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.