Jump to content

if table exists


Vivid Lust

Recommended Posts

Here's part of a piece of code where I check if a table exists, if it doesn't then it creates it,

 

if(!(mysql_query("SELECT * FROM $seller")))
        {
//doesn't exist then...	
$sql2 = "CREATE TABLE p" . $id . "(
id int(6) primary key NOT NULL auto_increment,
`site` VARCHAR( 30 ),
`ts` TIMESTAMP( 50 ),
`success` VARCHAR( 5 )
)";
mysql_query( $sql2, $link )
or die( mysql_error() );
        }
        else{
//does exist then...

echo "already exists!!"; 

        }

 

The problem is that the script keeps on echoing "Table 'p1' already exists" (as the $id = 1); and it doesn't echo  "already exists!!" like I want it to...

 

Any help on fixing this???

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/122575-if-table-exists/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.