ambo Posted October 29, 2008 Share Posted October 29, 2008 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 More sharing options...
trq Posted October 29, 2008 Share Posted October 29, 2008 Variables are not interpolated within single quotes so your $sql string needs be in double quotes. Link to comment https://forums.phpfreaks.com/topic/130639-help-with-creating-table/#findComment-677830 Share on other sites More sharing options...
ambo Posted October 29, 2008 Author Share Posted October 29, 2008 Thanks Link to comment https://forums.phpfreaks.com/topic/130639-help-with-creating-table/#findComment-677833 Share on other sites More sharing options...
ambo Posted October 29, 2008 Author Share Posted October 29, 2008 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 Link to comment https://forums.phpfreaks.com/topic/130639-help-with-creating-table/#findComment-677848 Share on other sites More sharing options...
trq Posted October 29, 2008 Share Posted October 29, 2008 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. Link to comment https://forums.phpfreaks.com/topic/130639-help-with-creating-table/#findComment-677860 Share on other sites More sharing options...
revraz Posted October 29, 2008 Share Posted October 29, 2008 Remove the comma after resource text Link to comment https://forums.phpfreaks.com/topic/130639-help-with-creating-table/#findComment-677870 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.