Jump to content

CREATE TABLE with POST value


BrianM

Recommended Posts

I'm trying to have my script create a table based upon the value that is inserted into the projectnumber input. Something along the lines of:

 

$insert_two = "CREATE TABLE `$_POST['projectnumber']`
(
PermitProcess varchar(40),
Req char(3),
SubmittalDate date,
CommentsReceivedDate1 date,
ResubmitDate1 date,
CommentsReceivedDate2 date,
ResubmitDate2 date,
CommentsReceivedDate3 date,
ResubmitDate3 date,
CommentsReceivedDate4 date,
ResubmitDate4 date,
ApprovalDate date,
PermitNumber varchar(10),
CoCReqDate date,
CoCSubmittalDate date
)";
mysql_query($insert_two, $mysql_connect);

 

The only thing I've found wrong is my syntax with trying to set the table name with my POST value. Is what I'm wondering is, does anyone know the correct syntax to write

 

$insert_two = "CREATE TABLE `$_POST['projectnumber']`

 

I'm not sure how to write out the correct format and syntax with the backticks and $_POST['projectnumber'].

Link to comment
Share on other sites

 "CREATE TABLE '{$_POST['projectnumber']}'

 

As a side note, be careful of your single quotes - the outside single quotes you were using around the post variable were not standard quotes, and as such would have failed even if you had used the syntax I used above. Did you copy them out of a word file or something?

Link to comment
Share on other sites

I actually was referring to the MySQL website, which is where I found out that information. Oh, and it's because I'm using numbers for table names instead of letters, and I heard backticks are the only thing that work with MySQL when creating tables with numbers in them.

Link to comment
Share on other sites

Ah, haku, thank you very much! It works, but like I said, I have to replace the '' with `` since I am using numbers instead of letters.

 

And stuffradio, thank you for the suggestion, but this will only be on a LAN at my fathers work office. I'm using HTML, PHP and a MySQL database to create a project tracking system for his engineering company so that there is no need to use a filing cabinet and folders with thousands of unorganized papers any longer. No need to worry about security in this case. :o) Thanks for the suggestion though.

 

Again, thanks you two!!!

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.