Vivid Lust Posted August 25, 2008 Share Posted August 25, 2008 hey, this mysql query comes back with no errors but keeps on creating the table "$seller" instead of the data assigned to the identifier. I need some help so the table created is the value of $seller! Query: <?php mysql_query("CREATE TABLE '$seller'( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), rating VARCHAR(30), feedback VARCHAR(250)) "); ?> rest of script: <?php //get database info require("db.php"); //set variables $dbname = 'ebay'; //get form data $seller = $_POST['seller']; $select = $_POST['select']; $feedback = $_POST['feedback']; //connect to database mysql_select_db($dbname); //checks if table exists (checks if seller exists also) $check = mysql_query("SELECT * FROM $seller LIMIT 0,1"); if ($check){ //if the seller does exist do this... echo "table exists"; }else{ //if the seller doesn't exist do this... mysql_query("CREATE TABLE '$seller'( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), rating VARCHAR(30), feedback VARCHAR(250)) "); echo "Table Created!"; } ?> Thanks for any help in advanced! Quote Link to comment Share on other sites More sharing options...
revraz Posted August 25, 2008 Share Posted August 25, 2008 Remove the single quotes from around it? Quote Link to comment Share on other sites More sharing options...
obsidian Posted August 25, 2008 Share Posted August 25, 2008 It sounds as though your $seller variable doesn't really contain the data you are expecting. You are assigning the data from $_POST['seller'], but are you positive that the post variable is being set as intended? Try echoing out your query strings before actually executing them. Once you are sure they reflect what you are after, you can execute them successfully. Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted August 26, 2008 Author Share Posted August 26, 2008 I echoed it out on that page and it does display the form data. I deleted the table named $seller in the database and now the script isnt creating a table at all ??? Any help guys? Quote Link to comment Share on other sites More sharing options...
Vivid Lust Posted August 26, 2008 Author Share Posted August 26, 2008 I commented out some lines so the script looks like this: <?php //get database info require("db.php"); //set variables $dbname = 'ebay'; //get form data $seller = $_POST['seller']; $select = $_POST['select']; $feedback = $_POST['feedback']; //connect to database mysql_select_db($dbname); //checks if table exists (checks if seller exists also) //$check = mysql_query('SELECT * FROM tbl WHERE tbl=="$seller" LIMIT 0,1'); //if ($check){ //if the seller does exist do this... //echo "table exists"; //}else{ //if the seller doesn't exist do this... mysql_query('CREATE TABLE "$seller"( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), rating VARCHAR(30), feedback VARCHAR(250)) '); //echo "didnt exist, now created"; echo $seller; //} ?> <b>works?</b> Still the table doesnt get created... this is weird? Quote Link to comment Share on other sites More sharing options...
revraz Posted August 26, 2008 Share Posted August 26, 2008 Now you have a single quote around your string which is wrong. mysql_query("CREATE TABLE $seller ( id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), rating VARCHAR(30), feedback VARCHAR(250)) "); Use mysql_error() after the query so you can see what error is being generated. Quote Link to comment Share on other sites More sharing options...
fenway Posted August 26, 2008 Share Posted August 26, 2008 You can't add a primary key with that syntax in the middle of the column spec. Use this: CREATE TABLE $seller ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, rating VARCHAR(30), feedback VARCHAR(250)) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.