Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 962613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T01:32:10+00:00 2026-05-16T01:32:10+00:00

I found out how to find if the database exists with this code: if(mysql_select_db(‘db-name’))

  • 0

I found out how to find if the database exists with this code:

if(mysql_select_db('db-name'))
return true;

But I would like to check the tables inside the database. Here is the code:

error_reporting(0);
session_start();

global $_ERROR;

$_ERROR = array();
$installed = false;

if($_POST)
{
    $num = 0;
    foreach($_POST as $key=>$value)
    {
        if(strlen(str_replace(" ","",$value))<=0 && $key!='db_pass')
        {
            $_ERROR[$key] = 'class="error"';
            $num ++;
        }
    }
    if($num>0)
    {
        $_ERROR['text'] = 'Please fill in all fields';
    }
    else
    {
        // Create Database
        $con = mysql_connect($_POST['db_server'],$_POST['db_user'],$_POST['db_pass']);
        if (!$con) {
            $_ERROR['text'] = 'There was an error connecting to your database';
        }
        else
        {
            if(mysql_select_db($_POST['db_name'])){

            }
            $db = mysql_select_db($_POST['db_name'],$con);
            if(!$db)
            {
                $_ERROR['text'] = 'Could not select database';
            }
            else
            {

                foreach($_POST as $key=>$value)
                {
                    $_POST[$key] = mysql_real_escape_string($value,$con);
                }

                $sql = 'SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
                        CREATE TABLE `active_guests` (
                        `ip` varchar(15) collate latin1_general_ci NOT NULL,
                        `timestamp` int(11) unsigned NOT NULL,
                        PRIMARY KEY  (`ip`)
                        );';
                mysql_query($sql,$con) or die(mysql_error());
                $sql = 'CREATE TABLE `active_users` (
                        `username` varchar(30) collate latin1_general_ci NOT NULL,
                        `timestamp` int(11) unsigned NOT NULL,
                         PRIMARY KEY  (`username`)
                        );';
                mysql_query($sql,$con) or die(mysql_error());
                $sql = 'CREATE TABLE `banned_users` (
                        `username` varchar(30) collate latin1_general_ci NOT NULL,
                        `timestamp` int(11) unsigned NOT NULL,
                        PRIMARY KEY  (`username`)
                        );';
                mysql_query($sql,$con) or die(mysql_error());
                $sql = "CREATE TABLE `forum` (
                        `postid` bigint(20) NOT NULL auto_increment,
                        `author` varchar(255) collate latin1_general_ci NOT NULL default '',
                        `title` varchar(255) collate latin1_general_ci NOT NULL default '',
                        `post` mediumtext collate latin1_general_ci NOT NULL,
                        `showtime` varchar(255) collate latin1_general_ci NOT NULL default '',
                        `realtime` bigint(20) NOT NULL default '0',
                        `lastposter` varchar(255) collate latin1_general_ci NOT NULL default '',
                        `numreplies` bigint(20) NOT NULL default '0',
                        `parentid` bigint(20) NOT NULL default '0',
                        `lastrepliedto` bigint(20) NOT NULL default '0',
                        `author_avatar` varchar(30) collate latin1_general_ci NOT NULL default 'default',
                        `type` varchar(2) collate latin1_general_ci NOT NULL default '1',
                        `stick` varchar(6) collate latin1_general_ci NOT NULL default '0',
                        `numtopics` bigint(20) NOT NULL default '0',
                        `cat` bigint(20) NOT NULL,
                        PRIMARY KEY  (`postid`)
                        );";
                mysql_query($sql,$con) or die(mysql_error());
                $sql = "CREATE TABLE `messages` (
                        `id` int(11) NOT NULL auto_increment,
                        `reciever` varchar(25) NOT NULL default '',
                        `sender` varchar(25) NOT NULL default '',
                        `subject` text NOT NULL,
                        `message` longtext NOT NULL,
                        `recieved` enum('1','0') default '0',
                        PRIMARY KEY  (`id`)
                        );";
                mysql_query($sql,$con) or die(mysql_error());           
                $sql = "CREATE TABLE `news` (
                        `id` int(11) NOT NULL auto_increment,
                        `titre` varchar(255) collate latin1_general_ci NOT NULL,
                        `contenu` text collate latin1_general_ci NOT NULL,
                        `timestamp` bigint(20) NOT NULL default '0',
                        PRIMARY KEY  (`id`)
                        );";
                mysql_query($sql,$con) or die(mysql_error());   
                $sql = "CREATE TABLE `settings` (
                        `id` int(11) NOT NULL auto_increment,
                        `name` varchar(25) NOT NULL default '',
                        `value` varchar(20) NOT NULL,
                        PRIMARY KEY  (`id`)
                        );";
                mysql_query($sql,$con) or die(mysql_error());
                $sql = "CREATE TABLE `users` (
                        `username` varchar(30) collate latin1_general_ci NOT NULL,
                        `password` varchar(32) collate latin1_general_ci default NULL,
                        `userid` varchar(32) collate latin1_general_ci default NULL,
                        `userlevel` tinyint(1) unsigned NOT NULL,
                        `email` varchar(50) collate latin1_general_ci default NULL,
                        `timestamp` int(11) unsigned NOT NULL,
                        `web` varchar(90) collate latin1_general_ci default 'Sorry, i dont have a website.',
                        `country` varchar(90) collate latin1_general_ci NOT NULL,
                        `avatar` varchar(30) collate latin1_general_ci NOT NULL default 'default',
                        `status` varchar(50) collate latin1_general_ci NOT NULL,
                        `pm_count` int(11) NOT NULL default '0',
                        `statusmessage` mediumtext COLLATE latin1_general_ci NOT NULL,
                        PRIMARY KEY (`username`)
                        );";        
                mysql_query($sql,$con) or die(mysql_error());
                $pass = md5($_POST['password']);
                $sql = "INSERT INTO `users` VALUES ('$_POST[name]', '$pass', '0', '9', '$_POST[email]', '', '', '', 'default', '', '0', 'Hello world!')";
                mysql_query($sql,$con) or die(mysql_error());
                $sql = "INSERT INTO `settings` VALUES (1, 'update', '0')";
                mysql_query($sql,$con) or die(mysql_error());
                $sql = "INSERT INTO `settings` VALUES (2, 'title', '$_POST[sitename]')";
                mysql_query($sql,$con) or die(mysql_error());
                $sql = "INSERT INTO `settings` VALUES (3, 'frontnews', '0')";
                mysql_query($sql,$con) or die(mysql_error());
                $sql = "INSERT INTO `settings` VALUES (4, 'headercolor', '#7387a7')";
                mysql_query($sql,$con) or die(mysql_error());
                $sql = "INSERT INTO `settings` VALUES (5, 'numpms', '50')";
                mysql_query($sql,$con) or die(mysql_error());


                $file = fopen("db.php","r");
                $data = fread($file, 500000);
                fclose($file);

                $data = str_replace('define("INSTALLED",FALSE);','define("INSTALLED",TRUE);',$data);
                $data = str_replace('HOST',$_POST['db_server'],$data);
                $data = str_replace('USER_',$_POST['db_user'],$data);
                $data = str_replace('PASSWORD',$_POST['db_pass'],$data);
                $data = str_replace('DBNAME',$_POST['db_name'],$data);
                $data = str_replace('EMAIL_NAME',$_POST['email_name'],$data);
                $data = str_replace('_EMAIL',$_POST['email'],$data);

                $file = fopen("db.php","w");
                fwrite($file, $data, 500000);
                fclose($file);

                header("Location: ../index.php");
            }
        }
    }
}

$_POST['siteurl'] = str_replace("/includes/install.php","","http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);

?>

The rest is html, so it’s no use. Basically, if i run this install script again after installing, it will give me an error saying that the table “active guest” already exists. (its the first table created, so its always this one showing.)

I’m trying to add a checking of the tables to tell the script: the tables already exist so don’t modify them and just create the db.php file without touching the database.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T01:32:10+00:00Added an answer on May 16, 2026 at 1:32 am

    You can just amend your SQL:

    CREATE TABLE IF NOT EXISTS `tablename`
    

    Reference MySQL docs here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I found out this morning that proc.new works in a class initialize method, but
I just found out how to validate my database input before saving it, but
While trying to find an answer to Android Jasper Reporting I found out that
I have found many similar posts and even tried to find out how to
I found out opencv sample face detection example for android but it is detecting
I found out during the debug that my db is in: /data/data/package-name/databases/... how can
I have a Java application and I would like to find out the location
My database fields are not populating but the page is confirming that it exists.
Im using a DB2 Database. What would be a suitable SQL query to find
I found out about GWT's CustomScrollPanel and how you can customize the scroll bar,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.