Jump to content

create table not working


Vivid Lust

Recommended Posts

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.