Jump to content

Recommended Posts

Hi

I'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 help
Thx
Link to comment
https://forums.phpfreaks.com/topic/14819-query-problem/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/14819-query-problem/#findComment-59209
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/14819-query-problem/#findComment-59223
Share on other sites

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....
Link to comment
https://forums.phpfreaks.com/topic/14819-query-problem/#findComment-59228
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.