CREATE TABLE `testt` ( `lname` varchar(250) NOT NULL default '', `email` varchar(250) NOT NULL default '',`ukey` int(11) NOT NULL auto_increment, PRIMARY KEY (`ukey`) `ukey` int(11) NOT NULL auto_increment);
basically the page this is displayed on attempts to create this table create in a generic format, however the final string does not seem to be liked when I try and run the query.
the error is:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'ukey` int(11) NOT NULL auto_increment,)' at line 1
here is the php code I'm using:
<?php
// Database variables
$dbserver = "localhost"; //Server hosting the database
$database = ""; //place name of database here
$username = ""; //database username here
$password = ""; //database users password here
$tablename = ""; //database table name associated with this form
$dbh=mysql_connect ($dbserver, $username , $password) or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ($database) or die ('I cannot connect to the database because: ' . mysql_error());
$tqr = "CREATE TABLE `$tablename` (";
if (!empty($_REQUEST)) {
foreach ($_REQUEST as $k=>$v) {
${$k} = $v;
echo "$k = '$v'<BR>";
if ($t != $k) {
$tqr .= " `$k` varchar(250) NOT NULL default '',";
}
$t = $k;
}
}
$tqr .= "`ukey` int(11) NOT NULL auto_increment, PRIMARY KEY (`ukey`) `ukey` int(11) NOT NULL auto_increment,);";
$sql = 'CREATE TABLE `orders` (' . ' `lname` varchar(250) NOT NULL default \'\','
. ' `email` varchar(250) NOT NULL default \'\','
. ' `ukey` int(11) NOT NULL auto_increment,'
. ' PRIMARY KEY (`ukey`)'
. ' `ukey` int(11) NOT NULL auto_increment,)';
echo $sql . "<HR>" . $tqr . "<BR><BR>";
mysql_query($tqr,$dbh) or die('I cannot create the table because: ' . mysql_error());
if (mysql_query($tqr,$dbh)) {
echo "Successfully created table `orders`";
}
?>
if you want to see it on the server it is at: http://www.scriptinphp.com/formgentest/
thanks for all of the help in advance.