timmah1 Posted December 24, 2007 Share Posted December 24, 2007 Can you please try and tell what I'm doing wrong here? I keep getting this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''pg_conditions'( id INT NOT NULL AUTO_INCREMENT, INDEX KEY(id)' at line 1 Here is the script mysql_query("CREATE TABLE ".$_POST['link']."'( id INT NOT NULL AUTO_INCREMENT, INDEX KEY(id) ") or die(mysql_error()); echo "Table Created!"; Thank you in advance Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/ Share on other sites More sharing options...
revraz Posted December 24, 2007 Share Posted December 24, 2007 $table=$_POST['link']; mysql_query("CREATE TABLE '$table' ( id INT NOT NULL AUTO_INCREMENT, INDEX KEY(id) ") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422372 Share on other sites More sharing options...
wildteen88 Posted December 24, 2007 Share Posted December 24, 2007 use backticks when defining field/table names within your query and not single quotes: mysql_query('CREATE TABLE `'.$_POST['link'].`'( id INT NOT NULL AUTO_INCREMENT, INDEX KEY(id)") or die(mysql_error()); echo "Table Created!"; Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422377 Share on other sites More sharing options...
timmah1 Posted December 24, 2007 Author Share Posted December 24, 2007 I copied that identical to what you put revraz, and I get this You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''pg_conditions' ( id INT NOT NULL AUTO_INCREMENT, INDEX KEY(id)' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422380 Share on other sites More sharing options...
shocker-z Posted December 24, 2007 Share Posted December 24, 2007 use mysql_query('CREATE TABLE `'.$_POST['link'].`'( id INT NOT NULL AUTO_INCREMENT, INDEX KEY(id)') or die(mysql_error()); you had a stray " instead of ' Regards Liam Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422382 Share on other sites More sharing options...
papaface Posted December 24, 2007 Share Posted December 24, 2007 use backticks when defining field/table names within your query and not single quotes: mysql_query('CREATE TABLE `'.$_POST['link'].`'( id INT NOT NULL AUTO_INCREMENT, INDEX KEY(id)") or die(mysql_error()); echo "Table Created!"; Should be: mysql_query('CREATE TABLE `'.$_POST['link'].'` ( id INT NOT NULL AUTO_INCREMENT, INDEX KEY(id)') or die(mysql_error()); echo "Table Created!"; Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422383 Share on other sites More sharing options...
shocker-z Posted December 24, 2007 Share Posted December 24, 2007 didnt see that paperface so this is what u need mate.. mysql_query('CREATE TABLE `'.$_POST['link'].'` ( id INT NOT NULL AUTO_INCREMENT, INDEX KEY(id)') or die(mysql_error()); Liam Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422385 Share on other sites More sharing options...
timmah1 Posted December 24, 2007 Author Share Posted December 24, 2007 Thanks for all the replies, but I'm getting this error now You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'KEY(id)' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422390 Share on other sites More sharing options...
papaface Posted December 24, 2007 Share Posted December 24, 2007 try: mysql_query('CREATE TABLE `'.$_POST['link'].'` ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id)') or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422392 Share on other sites More sharing options...
timmah1 Posted December 24, 2007 Author Share Posted December 24, 2007 This is confusing the hell out of me. I tried that papaface, but got the error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422393 Share on other sites More sharing options...
papaface Posted December 24, 2007 Share Posted December 24, 2007 What does $_POST['link'] contain? Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422394 Share on other sites More sharing options...
timmah1 Posted December 24, 2007 Author Share Posted December 24, 2007 It contains a link field, right now, for this code The $_POST['link'] is pg_conditions I saw somewhere else that the code looked like this mysql_query('CREATE TABLE `back`,`'.$_POST['link'].'` ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id)') or die(mysql_error()); With back being the database name, but that gives me this error You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '`pg_conditions` ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id)' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422395 Share on other sites More sharing options...
timmah1 Posted December 24, 2007 Author Share Posted December 24, 2007 I got it to work, it was missing one ) mysql_query('CREATE TABLE `'.$_POST['link'].'` ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id))') or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422396 Share on other sites More sharing options...
timmah1 Posted December 24, 2007 Author Share Posted December 24, 2007 Thanks to everyone who helped me. Have a great Holiday!!! Quote Link to comment https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/#findComment-422397 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.