Page 1 of 1

embeding PHP variable in mysql_query

Posted: Sun Apr 22, 2012 7:47 am
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,

Re: embeding PHP variable in mysql_query

Posted: Sun Apr 22, 2012 8:44 am
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.

Re: embeding PHP variable in mysql_query

Posted: Sun Apr 22, 2012 9:05 am
by McInfo
The keyword VALUES is inappropriate in this context.