I am tring to create a new table into the database if the table name given is not present in database using Php .
This is the code that I am using .
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(!$conn)
{
die('Failed to connect to server: ' . mysql_error());
exit;
}
$db_selected = mysql_select_db($dbname);
if(!$db_selected)
{
$db_selected = " CREATE DATABASE $dbname ";
}
$usertb1 = mysql_query("select 1 from $usertb LIMIT 1");
if( $usertb1 !== FALSE )
{
$sql = "CREATE TABLE IF NOT EXISTS $usertb ( uid INT(20) AUTO_INCREMENT UNIQUE KEY NOT NULL,name VARCHAR(40),email varchar(40) PRIMARY KEY NOT NULL)";
}
$typetb1 = mysql_query("select 1 from $typetb LIMIT 1");
if( $typetb1 !== FALSE)
{
$sql1 = "CREATE TABLE IF NOT EXISTS $typetb( uid INT(20) NOT NULL, type ENUM('WEB','APP','CART') NOT NULL ,unsubscribe TINYINT(1) NOT NULL,bounce TINYINT(1) NOT NULL,complaint TINYINT(1) NOT NULL, PRIMARY KEY (uid,type), FOREIGN KEY(uid) WHERE promo_user(uid))";
}