I am trying to make a content management system using HTML and PHP so that I can create and maintain my product database in MySQL via my browser instead of at the command line. I have gotten as far as being able to create the table in HTML using PHP and getting it to create the table in MySQL For some reason, my PHP won't pass the all the table varibles to MySQL. It is passing the table name, table length, table type, and null/not null but for some reason it won't pass any primary key or auto-increment data to MySQL. Here is my code:
<?php
$sql = "create table $name (";
for ($i = 0; $i < $columns; $i++) {
$sql .= "$fname[$i] $type[$i]";
if ($key[$i] !="" and $null[$i] !="" and $extra[$i] !=""
and $length[$i] !="") {
$sql .= "($length[$i]) $null[$i] $key[$i] $extra[$i],";
} else if ($key[$i] !="" and $null[$i] !="" and $length[$i] !="") {
$sql .= "($length[$i]) $null[$i] $key[$i],"; }
else if ($null[$i] !="" and $length[$i] !="") {
$sql .= "($length[$i]) $null[$i],"; }
else if ($length[$i] !="") {
$sql .= "($length[$i]),"; }
else if ($null[$i] !="") {
$sql .= " $null[$i],"; }
else if ($null[$i] !="" and $key[$i] !="") {
$sql .= " $null[$i] $key[$i],"; }
else {
$sql .= ",";
}
}
$sql = substr($sql, 0, -1);
$sql .=")";
//connect to the database
$dbcnx = mysql_connect("localhost", "root", "");
mysql_select_db("softdist");
if (mysql_query($sql)) {
echo("<p>Table $name has been created.</p>");
} else {
echo("<p>Error creating table $name: " .
mysql_error() . "</p>");
exit();
}
?>
Any ideas or help or maybe some other site that can help me with these sort of problems? Thanks in advance.