roro
roro

Reputation: 723

Creating a dynamic table in MySql using PHP

Im trying to create tables in mysql dynamically in php

$usernametable="test".$usname;
    $create = ("CREATE TABLE $usernametable(
    id SMALLINT NOT NULL PRIMARY KEY,
    test1 SMALLINT, test2 SMALLINT, test3 SMALLINT )");


    $createtable = mysql_query($create, $conn) 
    or die ('Problem with query' . mysql_error());  

It doesnt seem to work and i dont even get an error message. What seems to be the problem?

Upvotes: 0

Views: 65

Answers (1)

ashok_p
ashok_p

Reputation: 749

Try this it is working for me

    $con = mysql_connect(<host>,<username>,<password>) or die(mysql_error());
    mysql_select_db(<database_name>,$con);
    $usernametable="test".$usname;
    $create = ("CREATE TABLE $usernametable(
    id SMALLINT NOT NULL PRIMARY KEY,
    test1 SMALLINT, test2 SMALLINT, test3 SMALLINT )");


    $createtable = mysql_query($create, $con) 
    or die ('Problem with query' . mysql_error()); 

Upvotes: 1

Related Questions