Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > PHP

Reply
 
LinkBack Thread Tools
Old June 4th, 2007, 05:19 AM   #1
Reputable Member
SuperMember
 

Join Date: Apr 2007
Location: Sydney
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 nate2099 will become famous soon enough
PHP SQL create table with variable name

Hi,

I have two questions, firstly can I create a table with the name of a variable using php?? This is what I'm trying:
Code:
$query="CREATE TABLE $quote_num 
(
ID int(7) NOT NULL auto_increment,
itemid varchar(10) NOT NULL,
itemdesc varchar(50) NOT NULL,
)"

EDIT----------------
Code:
mysql_query("CREATE TABLE '".$quote_num."' 
   (
   ID int(7) NOT NULL auto_increment,
   itemid varchar(10) NOT NULL,
   itemdesc varchar(50) NOT NULL,
   )"
); 
This doesn't work either... and neither of them give an error..

/EDIT------------------

Also, are there any security issues in the following scenario:

A company produces quote and saves to database. Sends an email to client with a link and query string containing quote number to client. Client clicks link and webpage retrieves quote from database. Client checks "accept quote" and submits.

Thanks,

Nathan.

Last edited by karinne; June 12th, 2007 at 08:26 AM.. Reason: Please use [php]...[/php] tags when displaying PHP code!
nate2099 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old June 4th, 2007, 06:12 AM   #2
Reputable Member
 

Join Date: Apr 2007
Location: Scotland
Age: 19
Posts: 236
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Blake121 will become famous soon enough
Re: PHP SQL create table with variable name

This should work... You have to use real escape string to make the data safe before using it with a database.

The mysql_error() part will give you a detailed error if something goes wrong. (Remove the mysql_error() part from a live website.);

Code:
$quote_num = mysql_real_escape_string($quote_num);
 
$sql="CREATE TABLE $quote_num
(
ID int(7) NOT NULL auto_increment,
itemid varchar(10) NOT NULL,
itemdesc varchar(50) NOT NULL,
)";
 
$query = mysql_query($sql) or die (mysql_error());
Blake121 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old June 4th, 2007, 08:51 AM   #3
Highly Reputable Member
 
masonbarge's Avatar
 

Join Date: Jan 2006
Location: Atlanta GA
Posts: 649
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 masonbarge will become famous soon enough
Re: PHP SQL create table with variable name

I can't see a syntax mistake in your original version but AFAIK you have to set a primary key on your auto-increment column. This is a mysql problem.
masonbarge is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old June 12th, 2007, 08:25 AM   #4
Reputable Member
SuperMember
 

Join Date: Apr 2007
Location: Sydney
Posts: 160
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 nate2099 will become famous soon enough
Re: PHP SQL create table with variable name

Hmm, thanks for your help. I couldn't get this to work so I had to do it another way, thanks anyway.
nate2099 is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
table , sql , php , create


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
variable classes CloudedVision PHP 4 February 13th, 2008 11:07 PM
is this variable right? geyids PHP 4 August 6th, 2007 05:45 PM
Am I using table-cell and table-row too much? idl HTML, XHTML and CSS 15 September 7th, 2006 08:55 AM
Need to align width of Float table with the table below Vertabase HTML, XHTML and CSS 4 March 8th, 2006 05:21 PM
..copy data from column A in Table A to column B in Table B? gecastill Databases 10 June 23rd, 2005 02:27 PM


Search Engine Optimization by vBSEO 3.2.0 RC8