Jump to content

Help with creating table


ambo

Recommended Posts

i have a form that i want to use to create a table in my data base and i was wondering the correct way to post the data into the sql command

//grabs the variables

$name = $_POST["time_name"];

//gets mysql info

include("dbconn.php");

 

$sql = 'CREATE TABLE $name ('

        . ' `name` TEXT NOT NULL, '

        . ' `location` TEXT NOT NULL, '

        . ' `description` TEXT NOT NULL, '

        . ' `start_month` INT(2) NOT NULL, '

        . ' `start_day` INT(2) NOT NULL, '

        . ' `start_year` INT(4) NOT NULL, '

        . ' `end_month` INT(2) NOT NULL, '

        . ' `end_day` INT(2) NOT NULL, '

        . ' `end_year` INT(4) NOT NULL, '

        . ' `resource` TEXT NOT NULL'

        . ' )'

        . ' ENGINE = myisam;';

MYSQL_QUERY($sql);

Link to comment
https://forums.phpfreaks.com/topic/130639-help-with-creating-table/
Share on other sites

It still isnt creating the table its posting the data but no phsyical table is being created in database so i echo what the sql is to see if its posting correctly

Start code

//grabs the variables

$name = $_POST["timename"];

//gets mysql info

include("dbconn.php");

 

$sql = "CREATE TABLE $name (

    name text NOT NULL,

    location text,

    description text,

    start_month text,

    start_day text,

    start_year text,

    end_month text,

    end_day text,

    end_year text,

resource text,

)";

MYSQL_QUERY($sql);

//success...

echo "$sql;"

 

And get

CREATE TABLE Thanks ( name text NOT NULL, location text, description text, start_month text, start_day text, start_year text, end_month text, end_day text, end_year text, resource text, );

Thanks is the value i typed in the form that posts to this page

I can' tread the yellow snippet you posted.

 

Firstly, why are you creating anew table for each user in the first place?

 

Secondly, replace....

 

MYSQL_QUERY($sql);

 

with....

 

mysql_query($sql) or die(mysql_error() . "<br />$sql");

 

And lest try and find out what the error might be.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.