3. MySQL Database Tables Creation PHP Script Logic Tutorial




Lesson Code: http://www.developphp.com/video/PHP/MySQL-Database-Tables-Creation-Script-Logic Learn to script table creation into your MySQL database to …

Original source


40 responses to “3. MySQL Database Tables Creation PHP Script Logic Tutorial”

  1. Php reports an error every time I use a parameter. Such as for "gender" or "userlevel".
    Parse error: syntax error, unexpected 'a' (T_STRING) in /Applications/MAMP/htdocs/db.php on line 29

  2. Proper table 'users'

    CREATE TABLE `users` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `username` VARCHAR(16) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_polish_ci',
    `email` VARCHAR(50) NOT NULL DEFAULT '0' COLLATE 'utf8mb4_polish_ci',
    `password` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_polish_ci',
    `gender` ENUM('m','f') NOT NULL COLLATE 'utf8mb4_polish_ci',
    `country` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_polish_ci',
    `website` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_polish_ci',
    `userlevel` ENUM('a','b','c','d') NOT NULL DEFAULT 'a' COLLATE 'utf8mb4_polish_ci',
    `avatar` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb4_polish_ci',
    `ip` VARCHAR(255) NOT NULL COLLATE 'utf8mb4_polish_ci',
    `signup` DATETIME NOT NULL,
    `lastlogin` DATETIME NOT NULL,
    `notescheck` DATETIME NOT NULL,
    `activated` ENUM('0','1') NOT NULL DEFAULT '0' COLLATE 'utf8mb4_polish_ci',
    PRIMARY KEY (`id`),
    UNIQUE INDEX `username` (`username`, `email`)
    )
    COLLATE='utf8mb4_polish_ci'
    ENGINE=InnoDB
    ;

  3. If you guys are using Xampp by example and want to use root as username without using a password. You need to put null value to the third argument in order to be able to pass the db name as fourth argument. The syntax of mysqli_connect will be: $db_conx = mysqli_connect("localhost", "root", null, "social");

    Hey Adam, thanks a lot for theses tutorials, even if english isn't my first language, you speak very clearly and make this easily understanable for foreign language speaker and newb like me.

    Comment created OK 🙂

  4. why this code is not working any sugestion ???

    <?php
    $con=mysql_connect("localhost","root","");
    mysql_select_db('contact');
    $vari="demotable_name";

    $sql= "CREATE TABLE '".$vari."'(id int(10) AUTO_INCREMENT PRIMARY KEY,name VARCHAR(30) NOT NULL,contact1 VARCHAR(15),contact2 VARCHAR(15),contact3 VARCHAR(30),email VARCHAR(30),email2 VARCHAR(30),email3 VARCHAR(30),website VARCHAR(40),address text(30))";

    if(mysql_query($sql))
    {
    echo "table created";
    }
    ?>

  5. Please Sir help me.I am facing in the problem.
    Please how ill i solve the problem.

    Connected Successfully!!
    Warning: mysql_query() expects parameter 2 to be resource, string given in /home/learnbiology24/public_html/make_my_tables.php on line 26
    Users table not Created Ok:

    Warning: mysql_query() expects parameter 2 to be resource, string given in /home/learnbiology24/public_html/make_my_tables.php on line 48
    UserOptions table not Created Ok:

    Warning: mysql_query() expects parameter 2 to be resource, string given in /home/learnbiology24/public_html/make_my_tables.php on line 69
    Friends table not Created Ok:

    Warning: mysql_query() expects parameter 2 to be resource, string given in /home/learnbiology24/public_html/make_my_tables.php on line 90
    Blockedusers table not Created Ok:

    Warning: mysql_query() expects parameter 2 to be resource, string given in /home/learnbiology24/public_html/make_my_tables.php on line 111
    Status table not Created Ok:

    Warning: mysql_query() expects parameter 2 to be resource, string given in /home/learnbiology24/public_html/make_my_tables.php on line 131
    Photos table not Created Ok:

    Warning: mysql_query() expects parameter 2 to be resource, string given in /home/learnbiology24/public_html/make_my_tables.php on line 153
    Notifications table not Created Ok:

  6. you would better improve that code by avoiding " redundant code" , so like you would do $quires[] = array(); and you start adding to it all your quires , then at the end , you would foreach it , so you avoid redundant code 🙂 , overall everything seems perfect ^_^

  7. can somebody pls help… when i tried to run the codes ..i'm getting this kinda problem..
    user table NOT created 🙁

    useroptions table NOT created 🙁

    friends table NOT created 🙁

    blockedusers table NOT created 🙁

    status table NOT created 🙁

    photos table NOT created 🙁

    notifications table NOT created 🙁

  8. Hello all. To those who are having trouble getting the tables to successfully create, it's most likely because when you are uploading to the ftp, most of us are uploading the db_conx.php file by itself. We're supposed to upload the ENTIRE php_includes FOLDER to the ftp, which should have the db_conx.php file in it. Since in the make_my_tables.php file we put the folder name in the include function. Adam mentions this at 2:43!

  9. WOW i did it right i thought i wouldnt be able to but i won, thanx buddy ur so awesome.
    I use WAMP and working on it cause my host server isn't functioning well with me.
    And fox watch out one little comma mistake can mess up ur work. 

  10. I know that my db-conx is connecting to my sql because I got the password error. I fixed the password and now all I am getting is a blank screen when I do /makemytables.php. Any idea? I don't know what I have done wrong.

  11. mY sQL cODE nO WORK hELP

    $tbl_users = "CREATE TABLE IF NOT EXISTS users(

        'id' INT(11)NOT NULL AUTO_INCREMENT,
        'firstname' VARCHAR(20) NOT NULL,
        'lastname' VARCHAR(20) NOT NULL,
        'email' VARCHAR(50) NOT NULL,
        'username' VARCHAR(20) NOT NULL,
        'password' VARCHAR(20) NOT NULL,
        'active' ENUM('0','1') NOT NULL DEFAULT '0'
        'gender' ENUM ('m','f') NOT NULL
        'website' VARCHAR(255) NULL,
        'country' VARCHAR(25) NOT NULL,
        'userlevel' ENUM('a','b','c','d') NOT NULL DEFAULT 'a',
        'avatar' VARCHAR(25) NOT NULL,
        'ip' VARCHAR(25) NOT NULL,
        'signup' DATETIME NOT NULL,
        'lastlogin' DATETIME NOT NULL,
        'notescheck' DATETIME NOT NULL
        'PRIMARY KEY' (id),
        'UNIQUE KEY' username (username,email)

    )";

  12. This is really a wonderful series! As I understand, this is cPanel based, while I m having Plesk in Windows. Installed Joomla also. I could set up the data base, but finding it difficult to set tables. The permissions settings, control panel etc are totally different. Can someone help me the similar way this wonderful Adam does

Leave a Reply