Results 1 to 2 of 2
  1. #1
    Join Date
    April 22nd, 2012
    embeding PHP variable in mysql_query

    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,

  2. #2
    Join Date
    June 29th, 2011
    I'm running on very little sleep so sorry if my answer isn't correct or elegant, but I don't see where you've declared your columns for the table. You need to add the columns prior to the "VALUES" section. Also, where's your insert statement?

    Create table first, then insert values.


    mysql_query(" CREATE TABLE' {$COOKIE['randid']}' (columnname1 VARCHAR2(10), columnname2 INT(4)" );
    INSERT INTO tablename VALUES ('myvarchar', '3');

  3. Newsletter Signup

+ Reply to Thread

Similar Threads

  1. Variable Pricing within Datafeed
    By MartyM-Deluxe in forum Programming / Datafeeds / Tools
    Replies: 4
    Last Post: July 17th, 2012, 04:52 PM
  2. URL variable unknown
    By Patrick Vesperman in forum ShareASale - SAS
    Replies: 4
    Last Post: August 7th, 2009, 01:54 PM
  3. What is this link variable?
    By Catwoman in forum Midnight Cafe'
    Replies: 0
    Last Post: November 1st, 2004, 01:56 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts