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
Share on other sites

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

Link to comment
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!";

Should be:

mysql_query('CREATE TABLE `'.$_POST['link'].'` ( id INT NOT NULL AUTO_INCREMENT, INDEX KEY(id)')  or die(mysql_error());  

echo "Table Created!";

Link to comment
Share on other sites

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

Link to comment
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.