Home > Back-end >  Unknown database 'bwapp'
Unknown database 'bwapp'

Time:07-18

I'm running windows 10, I'm using XAMPP as my web/sql server.

I downloaded bwapp, extracted the zipped file, edited bwapp\admin\setting.php file and altered db password to null, and lastly I hosted the bwapp folder in my localhost htdocs\ so I can access it through the web browser as shown in below image. bWAPP installation page

However when I click on the installation link (here), I get the following error:

Fatal error: Uncaught mysqli_sql_exception: Unknown database 'bwapp' in C:\xampp\htdocs\bWAPP_latest\bWAPP\install.php:40 Stack trace: #0 C:\xampp\htdocs\bWAPP_latest\bWAPP\install.php(40): mysqli_select_db(Object(mysqli), 'bWAPP') #1 {main} thrown in C:\xampp\htdocs\bWAPP_latest\bWAPP\install.php on line 40

So I went to install.php line 40 to view the code, here it is:

    // Checks if the database 'bWAPP' already exists
if(!mysqli_select_db($link,"bWAPP"))
{

    // Creates the database 'bWAPP'
    $sql = "CREATE DATABASE IF NOT EXISTS bWAPP";

    $recordset = $link->query($sql);

    if(!$recordset)
    {

        die("Error: " . $link->error);

    }

    // Selects the database 'bWAPP'
     mysqli_select_db($link,"bWAPP");

    // Creates the 'users' table
    $sql = "CREATE TABLE IF NOT EXISTS users (id int(10) NOT NULL AUTO_INCREMENT,login varchar(100) DEFAULT NULL,password varchar(100) DEFAULT NULL,";
    $sql.= "email varchar(100) DEFAULT NULL,secret varchar(100) DEFAULT NULL,activation_code varchar(100) DEFAULT NULL,activated tinyint(1) DEFAULT '0',";
    $sql.= "reset_code varchar(100) DEFAULT NULL,admin tinyint(1) DEFAULT '0',PRIMARY KEY (id)) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

    $recordset = $link->query($sql);

    if(!$recordset)
    {

        die("Error: " . $link->error);

    }

    // Populates the table 'users' with the default users
    $sql = "INSERT INTO users (login, password, email, secret, activation_code, activated, reset_code, admin) VALUES";
    $sql.= "('A.I.M.', '6885858486f31043e5839c735d99457f045affd0', '[email protected]', 'A.I.M. or Authentication Is Missing', NULL, 1, NULL, 1),";
    $sql.= "('bee', '6885858486f31043e5839c735d99457f045affd0', '[email protected]', 'Any bugs?', NULL, 1, NULL, 1)";

    $recordset = $link->query($sql);

    if(!$recordset)
    {

        die("Error: " . $link->error);

    }

    // Creates the table 'blog' 
    $sql = "CREATE TABLE IF NOT EXISTS blog (id int(10) NOT NULL AUTO_INCREMENT,owner varchar(100) DEFAULT NULL,";
    $sql.= "entry varchar(500) DEFAULT NULL,date datetime DEFAULT NULL,PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

    $recordset = $link->query($sql);

    if(!$recordset)
    {

        die("Error: " . $link->error);

    }

    // Creates the table 'visitors'
    $sql = "CREATE TABLE IF NOT EXISTS visitors (id int(10) NOT NULL AUTO_INCREMENT,ip_address varchar(50) DEFAULT NULL,";
    $sql.= "user_agent varchar(500) DEFAULT NULL,date datetime DEFAULT NULL,PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

    $recordset = $link->query($sql);             

    if(!$recordset)
    {

        die("Error: " . $link->error);

    }      
    
    // Creates the table 'movies' 
    $sql = "CREATE TABLE IF NOT EXISTS movies (id int(10) NOT NULL AUTO_INCREMENT,title varchar(100) DEFAULT NULL,";
    $sql.= "release_year varchar(100) DEFAULT NULL,genre varchar(100) DEFAULT NULL,main_character varchar(100) DEFAULT NULL,";
    $sql.= "imdb varchar(100) DEFAULT NULL,tickets_stock int(10) DEFAULT NULL,PRIMARY KEY (id)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

    $recordset = $link->query($sql);

    if(!$recordset)
    {

        die("Error: " . $link->error);

    }

    // Populates the table 'movies'
    $sql = "INSERT INTO movies (title, release_year, genre, main_character, imdb, tickets_stock) VALUES ('G.I. Joe: Retaliation', '2013', 'action', 'Cobra Commander', 'tt1583421', 100),";
    $sql.= "('Iron Man', '2008', 'action', 'Tony Stark', 'tt0371746', 53),";
    $sql.= "('Man of Steel', '2013', 'action', 'Clark Kent', 'tt0770828', 78),";
    $sql.= "('Terminator Salvation', '2009', 'sci-fi', 'John Connor', 'tt0438488', 100),";
    $sql.= "('The Amazing Spider-Man', '2012', 'action', 'Peter Parker', 'tt0948470', 13),";
    $sql.= "('The Cabin in the Woods', '2011', 'horror', 'Some zombies', 'tt1259521', 666),";
    $sql.= "('The Dark Knight Rises', '2012', 'action', 'Bruce Wayne', 'tt1345836', 3),";
    $sql.= "('The Fast and the Furious', '2001', 'action', 'Brian O\'Connor', 'tt0232500', 40),";
    $sql.= "('The Incredible Hulk', '2008', 'action', 'Bruce Banner', 'tt0800080', 23),";
    $sql.= "('World War Z', '2013', 'horror', 'Gerry Lane', 'tt0816711', 0)";

    $recordset = $link->query($sql);

    if(!$recordset)
    {

        die("Error: " . $link->error);

    }
    
    // Creates the 'heroes' table
    $sql = "CREATE TABLE IF NOT EXISTS heroes (id int(10) NOT NULL AUTO_INCREMENT,login varchar(100) DEFAULT NULL,password varchar(100) DEFAULT NULL,secret varchar(100) DEFAULT NULL,";
    $sql.= "PRIMARY KEY (id)) ENGINE=InnoDB  DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";

    $recordset = $link->query($sql);             

    if(!$recordset)
    {

            die("Error: " . $link->error);

    }

    // Populates the table 'heroes' with the default users
    $sql = "INSERT INTO heroes (login, password, secret) VALUES";
    $sql.= "('neo', 'trinity', 'Oh why didn\'t I took that BLACK pill?'),";
    $sql.= "('alice', 'loveZombies', 'There\'s a cure!'),";
    $sql.= "('thor', 'Asgard', 'Oh, no... this is Earth... isn\'t it?'),";
    $sql.= "('wolverine', 'Log@N', 'What\'s a Magneto?'),";
    $sql.= "('johnny', 'm3ph1st0ph3l3s', 'I\'m the Ghost Rider!'),";
    $sql.= "('seline', 'm00n', 'It wasn\'t the Lycans. It was you.')";

    $recordset = $link->query($sql);

    if(!$recordset)
    {

            die("Error: " . $link->error);

    }


    $message = "bWAPP has been installed successfully!";

}

else
{

    $message = "The bWAPP database already exists...";

}

Note: That is part of setting.php file, contact me if you need the entire thing.

From what I understood, the code checks whether bWAPP database exists or no, if it doesn't, it creates it, yet I cant see where is the issue here.

CodePudding user response:

The bWAPP version is not compatible with PHP 8.1. Please contact the developer and submit a bug report with them.

As a workaround, you can use PHP 8.0 or older. It might also work if you manually execute CREATE DATABASE IF NOT EXISTS bWAPP in MySQL client, but that doesn't guarantee that the rest of the app will work.

  • Related