How to create a table in PHP with MySQL?

Php creating a table in mysql using a variable as table name.?

  • Hi, Im trying to create a table in mysql using variable $signupemail as table name. Here is my code mysql_select_db("profiles",$connect); mysql_query("CREATE TABLE ".$signupemail." (FirstName VARCHAR(30), LastName VARCHAR(30), DateofBirth DATE)",$connect); I have already tried single quotes, double quotes, period strings and curly brackets. Anyone knows what is wrong here? Thanks! :)

  • Answer:

    its been a while since i worked with php, but it looks good to me. try setting the query as a variable $test="CREATE TABLE ".$signupemail." (FirstName VARCHAR(30), LastName VARCHAR(30), DateofBirth DATE)"; then print out test to make sure signupemail actually holds the value you expect it to EDIT: do mysql_query(test) or die("mysql error: " . mysql_error()); post the error result

Yang at Yahoo! Answers Visit the source

Was this solution helpful to you?

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.