Results 1 to 2 of 2
  1. #1
    Newbie
    Join Date
    April 22nd, 2012
    Posts
    1
    embeding PHP variable in mysql_query
    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,

  2. #2
    Newbie
    Join Date
    June 30th, 2011
    Posts
    9
    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.

    Example:

    Code:
    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, 05:52 PM
  2. URL variable unknown
    By Patrick Vesperman in forum ShareASale - SAS
    Replies: 4
    Last Post: August 7th, 2009, 02:54 PM
  3. What is this link variable?
    By Catwoman in forum Midnight Cafe'
    Replies: 0
    Last Post: November 1st, 2004, 02: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
  •