Hello, I have a script that among other things, creates a table with a variable being the table name. This worked fine when i was using the variable "$name".
Since then I've realized that i need the table name to be "$merchid" (primary key from previous table. I've used "$newid = mysql_insert_id();" to recall the last auto incremented primary key and this echoes just fine, but when i use $newid in place of $name, in the CREATE TABLE query the darn thing breaks, meaning no table is created. The rest of the form functions properly with this error.
Again, this was working fine when using $name from the form data. When i switch to using the primary key grabbed with mysql_insert_id(); it stops working.
Any help would be greatly appreciated!
//where images are saved
$target = "../logo/";
$target = $target . basename( $_FILES);
//info from form
// connect to db
mysql_connect("xxx", "xxx", "xxxx") or die(mysql_error()) ;
mysql_select_db("xxx") or die(mysql_error()) ;
//writes the form data to db
mysql_query("INSERT INTO `merchants` VALUES ( '$merchid','$name', '$type', '$tagline', '$keywords', '$address', '$city', '$state', '$zip', '$phone', '$fax', '$web', '$email', '$created', '$modified', '$status', '$uploaded', '$mini')") ;
// calls the last unique id that mysql generated
$newid = mysql_insert_id();
// creates new table
mysql_query ("CREATE TABLE $newid (
id INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
created TIMESTAMP DEFAULT NOW())");
// inserts last entered unique id to the new table
mysql_query("INSERT INTO $newid VALUES ('id', '$newid', 'custid', 'modified', 'created')");
//limits upload file size
if ($uploaded_size > 350000)
echo "Your file is too large.<br>";
//file type limits
if ($uploaded_type =="text/php")
echo "No PHP files<br>";
Echo "Sorry your file was not uploaded";
//Writes file to server
//Tells you if its all ok
echo "The file ". basename( $_FILES). " has been uploaded, and your information has been added to the directory";
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";