0

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?

1
  • Can you show the content of variable $create? // echo $create Commented May 31, 2014 at 6:10

1 Answer 1

1

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()); 
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.