I'm creating a php script that can create a table on a selected database. I finally got it right. But when I enter the code which allows a field to be the primary key, my code doesn't work. Here is my code:
<?php
include ("db_con.php");
echo '<form action="table_add.php" method="post">';
echo "Table Name:".'<input type="text" maxlength="20" name="TableName">';
echo "Field1(primary key):".'<input type="text" maxlength="20" name="f1">';
echo "Field2:".'<input type="text" maxlength="20" name="f2">';
echo "Field3:".'<input type="text" maxlength="20" name="f3">';
echo "Field4:".'<input type="text" maxlength="20" name="f4">';
echo '<input type="submit" name="submit" value="submit">';
if(isset($_POST["submit"]))
{
$tableName=$POST["TableName"];
$f1=$POST["f1"];
$f2=$POST["f2"];
$f3=$POST["f3"];
$f4=$_POST["f4"];
$create="CREATE TABLE $tableName (PRIMARY KEY $f1 int(2), $f2 varchar(15),$f3 varchar(15), $f4 int(2))";
mysql_query($create,$con);
echo "add succeedded!";
}
echo "</form>";
mysql_close($con);
?>
is my code wrong? I'll wait for your reply, thanks.