
Jawaad
By: a guest on Aug 21st, 2008 | syntax:
PHP | size: 1.79 KB | hits: 346 | expires: Never
<?php
// UPLOAD CSV CUSTOM
// Ver. 1.0
// by Jawaad
// zaibatsu@gmail.com
// file: create table
?>
<form method="post">
<br><br>
<h2>Create Table</h2>
Table Name: <input name="table_name">
<input type="hidden" value="0" id="theValue" /><a href="javascript:;" onclick="addElement();">+ Add field</a>
<p>
<div id="myDiv"> </div>
<input type="hidden" name="create_table" value="1">
<input type="submit" name="submit" value="Create Table">
</form>
<?php
if($_POST[create_table]=="1") {
//$kode = array($_POST[kode]);
$table_name = $_POST[table_name];
echo "Check <b>".$table_name."</b><br>";
//print_r($_POST[kode]);
if($table_name != "" && $_POST[kode] != "") {
foreach ($_POST[kode] as $field_arr) {
$field = $_POST["field".$field_arr.""];
$tipe = $_POST["tipe".$field_arr.""];
if($tipe == "TEXT") {$db_tipe = "varchar(255),";}
elseif($tipe == "NUMERIC") {$db_tipe = "bigint(20),";}
elseif($tipe == "NUMERIC-2-DECIMAL") {$db_tipe = "float(10,2),";}
elseif($tipe == "LONG-TEXT") {$db_tipe = "text NOT NULL,";}
elseif($tipe == "DATE") {$db_tipe = "date NOT NULL,";}
elseif($tipe == "DATE-TIME") {$db_tipe = "datetime NOT NULL,";}
$the_fields .= "`" . $field . "` " . $db_tipe . "\n";
}
$sql = "
CREATE TABLE IF NOT EXISTS `".$table_name."` (
`id` bigint(20) NOT NULL auto_increment,
".$the_fields."
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
";
if(!$ex) {
echo "Sorry,... Error...<br>";
} else {
echo "Table <b>".$table_name."</b> created.<br>";
}
} else {
echo "Sorry,... Error... Please fill the table name and the fields...<br>";
}
/*
echo "<pre>";
echo $sql;
echo "</pre>";
*/
}
?>