embeding PHP variable in mysql_query

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
smaboud
Forum Newbie
Posts: 1
Joined: Sun Apr 22, 2012 7:04 am

embeding PHP variable in mysql_query

Post by smaboud »

Hi

I am trying to create a table using mesql_query to create table and name it with a number generated by a PHP random variable.


$status = mysql_select_db($database);
<!--- has been generated from another page i am able to insert it in to an existing table----> $var= $_COOKIE['randid'];

mysql_query(" CREATE TABLE `{$var}` VALUES (
`userid_id` bigint(255))");



I thought there must be a problem with the type of value stored in the cookie as its an INT but it wasnt the right solution i have changed it to a string but im not yet able to create the table.

the generated number is a customer ID

Please help,
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: embeding PHP variable in mysql_query

Post by Celauran »

First, what error is it generating? Second, why are you trying to do this? Blindly creating tables seems like an exceedingly bad idea.
User avatar
McInfo
DevNet Resident
Posts: 1532
Joined: Wed Apr 01, 2009 1:31 pm

Re: embeding PHP variable in mysql_query

Post by McInfo »

The keyword VALUES is inappropriate in this context.
Post Reply