ViralStef Posted July 17, 2006 Share Posted July 17, 2006 HiI'm trying to generate a CREATE TABLE query:[code]$createtable_query = "CREATE TABLE '$componentname' ('ID' INT(10) UNSIGNED NOT NULL AUTO_INCREMENT" . $table_string . ")";$createtable_result = mysql_query($createtable_query) or die(mysql_error($createtable_query));[/code]$table_string is generated by the previous script.When I print $createtable_query, I get this result (just an example):[quote]CREATE TABLE 'componenttest' ('ID' INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, 'Name' VARCHAR(255) NOT NULL)[/quote]That looks like a correct query.Although, PHP warns:[quote]Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in c:\program files\easyphp1-8\www\cms\adminpanel\components\addcomponent.php on line 128[/quote](Line 128 is "$createtable_result = ... ")What is wrong with my query?Plz helpThx Quote Link to comment https://forums.phpfreaks.com/topic/14819-query-problem/ Share on other sites More sharing options...
Honoré Posted July 17, 2006 Share Posted July 17, 2006 1) try[code]$createtable_query = "CREATE TABLE '$componentname' ('ID' INT(10) UNSIGNED NOT NULL AUTO_INCREMENT" . $table_string . ")";mysql_query($createtable_query) or die(mysql_error());[/code]Your query should not return a result set for a CREATE TABLE command.2) AUTO_INCREMENT on a VARCHAR column is probably not what you want. Quote Link to comment https://forums.phpfreaks.com/topic/14819-query-problem/#findComment-59209 Share on other sites More sharing options...
ShogunWarrior Posted July 17, 2006 Share Posted July 17, 2006 I THINK the problem is your quoting, as far as I know single quotes are only used for literal quoting of data. When you are quoting resource names such as database and tables I think you use backticks: `` Quote Link to comment https://forums.phpfreaks.com/topic/14819-query-problem/#findComment-59216 Share on other sites More sharing options...
ViralStef Posted July 17, 2006 Author Share Posted July 17, 2006 HiI tried it without variable declaration, but it didn't work either.Indeed, I don't want AUTO_INCREMENT on a varchar column, but does my script have that result?Thx Quote Link to comment https://forums.phpfreaks.com/topic/14819-query-problem/#findComment-59217 Share on other sites More sharing options...
ViralStef Posted July 17, 2006 Author Share Posted July 17, 2006 What do you mean with backtips? Are that quotes that are not straight (like in PHPMyAdmin)? I tried this by copying those quotes from PHPMyAdmin into my script. I don't know how to type them. But I tried it, and it didn't work either:(!thx! Quote Link to comment https://forums.phpfreaks.com/topic/14819-query-problem/#findComment-59221 Share on other sites More sharing options...
ShogunWarrior Posted July 17, 2006 Share Posted July 17, 2006 Well instead of [code]"CREATE TABLE '$componentname'[/code]I think it should be [code]"CREATE TABLE `$componentname`[/code]For me, the backticks is in the top left of the keyboard, nothing happens when I press the button once, I have to press it twice and I get two backticks. Quote Link to comment https://forums.phpfreaks.com/topic/14819-query-problem/#findComment-59223 Share on other sites More sharing options...
ViralStef Posted July 17, 2006 Author Share Posted July 17, 2006 Hm, I can't find those backtips on my keyboard, but I can copy them for PHPMyAdmin.So, now I tried it with backtips and I get the following print result:[quote]CREATE TABLE `componenttest` (`ID` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT, `Name` VARCHAR(255) NOT NULL)[/quote]But still the same error.... Quote Link to comment https://forums.phpfreaks.com/topic/14819-query-problem/#findComment-59228 Share on other sites More sharing options...
ShogunWarrior Posted July 17, 2006 Share Posted July 17, 2006 This should work, you have to set ID to primary key because it is AUTO_INCREMENT:[code]CREATE TABLE `componenttest` (`ID` int( 10 ) UNSIGNED NOT NULL AUTO_INCREMENT ,`Name` varchar( 255 ) NOT NULL ,PRIMARY KEY ( `ID` ) ) [/code] Quote Link to comment https://forums.phpfreaks.com/topic/14819-query-problem/#findComment-59242 Share on other sites More sharing options...
ViralStef Posted July 17, 2006 Author Share Posted July 17, 2006 Solved:d!Indeed, primary key had to be set, and backtips had to be used!thx a lot ;D Quote Link to comment https://forums.phpfreaks.com/topic/14819-query-problem/#findComment-59510 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.