My following file is not working.
showing error in line 42 at else
I don't why
an instant help wud be highly appreciable
<html><head><title>Creating a table</title></head>
<body>
<?php
if(!$fields and !$db)
{
$form="<form action=\"$PHP_SELF\" method=\"post\">";
$form.= "How many fields are needed in the new table?";
$form.= "<br><input type=\"text\" name=\"fields\">";
$form.= "<input type=\"submit\" value=\"Submit\">";
echo($form);
}
else if(!$db)
{
$form ="<form action = \"$PHP_SELF\" method=\"post\">";
$form.="Database : <input type=\"text\" name = \"db\"> default=\"student\" <br>";
$form.="Table Name: <input type =\"text\" name=\"table\"><br>";
for ($i=0; $i <$fields; $i++)
{$form.="Column Name:<input type=\"text\" name=\"name[$i]\">";
$form.="Type: <select name=\"type[$i]\">";
$form.="<option value =\"char\">char</option>";
$form.="<option value =\"int\">int</option>";
$form.="<option value =\"decimal\">decimal</option>";
$form.="<option value =\"double\">double</option>";
$form.="<option value =\"date\">date</option>";
$form.="<option value =\"time\">time</option>";
$form.="<option value =\"datetime\">datetime</option>";
$form.="<option value =\"year\">year</option>";
$form.="<option value =\"timestamp\">timestamp</option>";
$form.="<option value =\"varchar\">varchar</option>";
$form.="<option value =\"text\">text</option>";
$form.="<option value =\"blob\">blob</option>";
$form.="<option value =\"enum\">enum</option>";
$form.="<option value =\"set\">set</option>";
$form.="</select>";
$form.="<input type =\"submit\" value=\"submit\">";
$form.="</form>"; echo($form);
}
else
{
#make the connection to mysql
$conn = @mysql_connect('localhost' ,'root', '') or die("Err:Conn");
#select the specified database
$rs = @mysql_select_db($db, $conn) or die("Err😃b");
#create the query
$sql = "create table $table (";
for ($i = 0; $i < count($name); $i++)
{
#fieldname and data type
$sql.="$name[$i] $type[$i]";
#allow size specification for char and varchar types
if(($type[$i]=="char") or ($type[$i] == "varchar"))
{
#if a size has been specified add it to the query
if($size[$i] !=" " ){ $sql.= "($size[$i])"; }
}
#if this is not the final field add a comma
if(($i+1) != count($name) ){$sql.=",";}
} $sql.=")";
########################################
#display the sql query
########################################
echo("SQL COMMAND: $sql <hr>");
#execute the query - attempt to create the table
$result = mysql_query($sql,$conn) or die)"Err:Query");
if ($result){echo ("RESULT : table \"$table\" has been created");}
}
?>
</body>
</html>