Vivid Lust Posted September 3, 2008 Share Posted September 3, 2008 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 More sharing options...
discomatt Posted September 3, 2008 Share Posted September 3, 2008 Can we make the assumption that $seller = 'p'.$id ? If not, I really don't get what your script is doing. Link to comment https://forums.phpfreaks.com/topic/122575-if-table-exists/#findComment-632890 Share on other sites More sharing options...
GingerRobot Posted September 3, 2008 Share Posted September 3, 2008 I have to question why you'd want to create a new table for each ID. You almost certainly shouldn't be doing this. You might want to read up on database normalisation. Link to comment https://forums.phpfreaks.com/topic/122575-if-table-exists/#findComment-632895 Share on other sites More sharing options...
Vivid Lust Posted September 3, 2008 Author Share Posted September 3, 2008 I changed seller to id (as it was meant to be that XD); although still the same thing happens :s And id, as in user id... help? Link to comment https://forums.phpfreaks.com/topic/122575-if-table-exists/#findComment-632903 Share on other sites More sharing options...
discomatt Posted September 3, 2008 Share Posted September 3, 2008 Echo your query and try it in the SQL console. Make sure the query is as you expect. Link to comment https://forums.phpfreaks.com/topic/122575-if-table-exists/#findComment-632913 Share on other sites More sharing options...
Vivid Lust Posted September 3, 2008 Author Share Posted September 3, 2008 Yeah, query works Link to comment https://forums.phpfreaks.com/topic/122575-if-table-exists/#findComment-632933 Share on other sites More sharing options...
discomatt Posted September 3, 2008 Share Posted September 3, 2008 Both? Link to comment https://forums.phpfreaks.com/topic/122575-if-table-exists/#findComment-632935 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.