I had been searching all day long and could not find any solutions.

MY CODE:

<?php
include_once("php_includes/db_connect.php");
$tbl_users = "CREATE TABLE IF NOT EXISTS users (
id INT(11) NOT NULL AUTO_INCREMENT,
username VARCHAR(16) NOT NULL,
email VARCHAR(255) NOT NULL,
password VARCHAR(255) NOT NULL,
gender ENUM('m','f') NOT NULL,
country VARCHAR(255) NOT NULL,
userlevel ENUM('a','b','c','d' NOT NULL,
avatar VARCHAR(255) NULL,
ip VARCHAR(255) NOT NULL,
signup DATETIME NOT NULL,
lastlogin DATETIME NOT NULL
notescheck DATETIME NOT NULL,
activated ENUM('0','1') NOT NULL DEFAULT '0',
primary key (id),
UNIQUE KEY username (username, email)
)";
$query = mysqli_query($db_connect, $tbl_users); THIS IS LINE 20
if ($query === TRUE) {
echo "<h3>user table created OK 🙂 </h3>";
} else {
echo "<h3>user table NOT created 🙁 </h3>";
}

THE ERROR:

Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in /home/www/URL/make_my_table.php on line 20
user table NOT created 🙁

    What is the code that declares $db_connect?

      <?php
      $db_connect = mysql_connect('localhost', 'dbnamel', 'dbpwd');
      mysql_select_db('divitiae_social');
      $link = mysqli_connect('localhost', 'dbname', 'dbpwd');
      if (!$link) {
      die('Could not connect: ' . mysqli_error());
      }
      echo 'Connected successfully';
      mysqli_close($link);
      ?>

      RESULT:

      Connected successfully

        Well, that explains the problem: for some reason you're using mysql_connect instead of mysqli_connect, and then assigning the result to $db_connect. You do use mysqli_connect for $link, but that appears unused in the earlier code. My guess is that you actually want something like:

        <?php
        $db_connect = mysqli_connect('localhost', 'dbname', 'dbpwd', 'divitiae_social');
        if (!$db_connect) {
            die('Could not connect: ' . mysqli_connect_error());
        }

        the above code connected me successfully but it did not create the database

        and got me the following error

        user table NOT created 🙁

        useroptions table NOT created 🙁

        friends table created OK

        Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/www/divitiae.net.co/make_my_table.php on line 66
        blockedusers table NOT created

        Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/www/divitiae.net.co/make_my_table.php on line 83
        status table NOT created

        Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/www/divitiae.net.co/make_my_table.php on line 99
        photos table NOT created 🙁

        Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /home/www/divitiae.net.co/make_my_table.php on line 116
        notifications table NOT created 🙁

          it only created the database for friends but not the users and others
          both have same query syntax.

          code for users:
          <?php
          include_once("php_includes/db_connect.php");
          $tbl_users = "CREATE TABLE IF NOT EXISTS users (
          id INT(11) NOT NULL AUTO_INCREMENT,
          username VARCHAR(16) NOT NULL,
          email VARCHAR(255) NOT NULL,
          password VARCHAR(255) NOT NULL,
          gender ENUM('m','f') NOT NULL,
          country VARCHAR(255) NOT NULL,
          userlevel ENUM('a','b','c','d' NOT NULL,
          avatar VARCHAR(255) NULL,
          ip VARCHAR(255) NOT NULL,
          signup DATETIME NOT NULL,
          lastlogin DATETIME NOT NULL
          notescheck DATETIME NOT NULL,
          activated ENUM('0','1') NOT NULL DEFAULT '0',
          primary key (id),
          UNIQUE KEY username (username, email)
          )";
          $query = mysqli_query($db_connect, $tbl_users);
          if ($query === TRUE) {
          echo "<h3>user table created OK 🙂 </h3>";
          } else {
          echo "<h3>user table NOT created 🙁 </h3>";
          }

          CODE FOR FRIENDS:

          $tbl_friends = "CREATE TABLE IF NOT EXISTS friends (
          id INT(11) NOT NULL AUTO_INCREMENT,
          user1 VARCHAR(16) NOT NULL,
          user2 VARCHAR(16) NOT NULL,
          datemade DATETIME NOT NULL,
          accepted ENUM('0','1') NOT NULL DEFAULT '0',
          PRIMARY KEY (id)
          )";
          $query = mysqli_query($db_connect, $tbl_friends);
          if ($query === TRUE) {
          echo "<h3>friends table created OK 🙂 </h3>";
          } else {
          echo "<h3>friends table NOT created 🙁 </h3>";
          }

            :p Thank you so much laserlight!!!:p

            I went through my create database line by line and found some errors.

            but it was the connect code that solve the errors.

            Thanks for your help!!!:p

              5 years later
              Write a Reply...