Posted by Jawaad on Thu 21 Aug 17:47
report abuse | download | new post
- <?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];
- //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 {
- }
- } else {
- echo "Sorry,... Error... Please fill the table name and the fields...<br>";
- }
- /*
- echo "<pre>";
- echo $sql;
- echo "</pre>";
- */
- }
- ?>
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.