Jump to content

[SOLVED] Create Tables with PHP


timmah1

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/83039-solved-create-tables-with-php/
Share on other sites

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!";

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

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!";

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

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.