- Jun 14, 2008
- 55
- 0
- 66
Hi, I have a csv file exported form excel:
File format is like this:
firstname,lastname,birthdate,city
john,smith,1905.06.07,new york
marry,lay,1985.02.02,birwa
harry,johnson,1936.01.09,moscow
how to make a "load csv" button on my form to load a text file that contains asingle line only like this:
john;smith;1905.06.07;new york
and to fill all the text field boxes on my form?
My form code below:
<?php require_once('Connections/my_MySQL.php'); ?>
<?php
// Load the common classes
require_once('includes/common/KT_common.php');
// Load the tNG classes
require_once('includes/tng/tNG.inc.php');
// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("");
// Make unified connection variable
$conn_my_MySQL = new KT_connection($my_MySQL, $database_my_MySQL);
// Start trigger
$formValidation = new tNG_FormValidation();
$tNGs->prepareValidation($formValidation);
// End trigger
// Make an insert transaction instance
$ins_location = new tNG_insert($conn_my_MySQL);
$tNGs->addTransaction($ins_location);
// Register triggers
$ins_location->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_location->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
// Add columns
$ins_location->setTable("location");
$ins_location->addColumn("firstname", "STRING_TYPE", "POST", "firstname");
$ins_location->addColumn("lastname", "STRING_TYPE", "POST", "lastname");
$ins_location->addColumn("birthdate", "DATE_TYPE", "POST", "birthdate");
$ins_location->addColumn("city", "STRING_TYPE", "POST", "city");
$ins_location->setPrimaryKey("id_location", "NUMERIC_TYPE");
// Execute all the registered transactions
$tNGs->executeTransactions();
// Get the transaction recordset
$rslocation = $tNGs->getRecordset("location");
$row_rslocation = mysql_fetch_assoc($rslocation);
$totalRows_rslocation = mysql_num_rows($rslocation);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
</head>
<body>
<?php
echo $tNGs->getErrorMsg();
?>
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
<table cellpadding="2" cellspacing="0" class="KT_tngtable">
<tr>
<td class="KT_th"><label for="firstname">Firstname:</label></td>
<td><input type="text" name="firstname" id="firstname" value="<?php echo KT_escapeAttribute($row_rslocation['firstname']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("firstname");?> <?php echo $tNGs->displayFieldError("location", "firstname"); ?> </td>
</tr>
<tr>
<td class="KT_th"><label for="lastname">Lastname:</label></td>
<td><input type="text" name="lastname" id="lastname" value="<?php echo KT_escapeAttribute($row_rslocation['lastname']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("lastname");?> <?php echo $tNGs->displayFieldError("location", "lastname"); ?> </td>
</tr>
<tr>
<td class="KT_th"><label for="birthdate">Birthdate:</label></td>
<td><input type="text" name="birthdate" id="birthdate" value="<?php echo KT_formatDate($row_rslocation['birthdate']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("birthdate");?> <?php echo $tNGs->displayFieldError("location", "birthdate"); ?> </td>
</tr>
<tr>
<td class="KT_th"><label for="city">City:</label></td>
<td><input type="text" name="city" id="city" value="<?php echo KT_escapeAttribute($row_rslocation['city']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("city");?> <?php echo $tNGs->displayFieldError("location", "city"); ?> </td>
</tr>
<tr class="KT_buttons">
<td colspan="2"><label>
<input type="submit" name="browse" id="browse" value="Load csv" />
</label>
<input type="submit" name="KT_Insert1" id="KT_Insert1" value="Insert record" />
</td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>
File format is like this:
firstname,lastname,birthdate,city
john,smith,1905.06.07,new york
marry,lay,1985.02.02,birwa
harry,johnson,1936.01.09,moscow
how to make a "load csv" button on my form to load a text file that contains asingle line only like this:
john;smith;1905.06.07;new york
and to fill all the text field boxes on my form?
My form code below:
<?php require_once('Connections/my_MySQL.php'); ?>
<?php
// Load the common classes
require_once('includes/common/KT_common.php');
// Load the tNG classes
require_once('includes/tng/tNG.inc.php');
// Make a transaction dispatcher instance
$tNGs = new tNG_dispatcher("");
// Make unified connection variable
$conn_my_MySQL = new KT_connection($my_MySQL, $database_my_MySQL);
// Start trigger
$formValidation = new tNG_FormValidation();
$tNGs->prepareValidation($formValidation);
// End trigger
// Make an insert transaction instance
$ins_location = new tNG_insert($conn_my_MySQL);
$tNGs->addTransaction($ins_location);
// Register triggers
$ins_location->registerTrigger("STARTER", "Trigger_Default_Starter", 1, "POST", "KT_Insert1");
$ins_location->registerTrigger("BEFORE", "Trigger_Default_FormValidation", 10, $formValidation);
// Add columns
$ins_location->setTable("location");
$ins_location->addColumn("firstname", "STRING_TYPE", "POST", "firstname");
$ins_location->addColumn("lastname", "STRING_TYPE", "POST", "lastname");
$ins_location->addColumn("birthdate", "DATE_TYPE", "POST", "birthdate");
$ins_location->addColumn("city", "STRING_TYPE", "POST", "city");
$ins_location->setPrimaryKey("id_location", "NUMERIC_TYPE");
// Execute all the registered transactions
$tNGs->executeTransactions();
// Get the transaction recordset
$rslocation = $tNGs->getRecordset("location");
$row_rslocation = mysql_fetch_assoc($rslocation);
$totalRows_rslocation = mysql_num_rows($rslocation);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="includes/skins/mxkollection3.css" rel="stylesheet" type="text/css" media="all" />
<script src="includes/common/js/base.js" type="text/javascript"></script>
<script src="includes/common/js/utility.js" type="text/javascript"></script>
<script src="includes/skins/style.js" type="text/javascript"></script>
<?php echo $tNGs->displayValidationRules();?>
</head>
<body>
<?php
echo $tNGs->getErrorMsg();
?>
<form method="post" id="form1" action="<?php echo KT_escapeAttribute(KT_getFullUri()); ?>">
<table cellpadding="2" cellspacing="0" class="KT_tngtable">
<tr>
<td class="KT_th"><label for="firstname">Firstname:</label></td>
<td><input type="text" name="firstname" id="firstname" value="<?php echo KT_escapeAttribute($row_rslocation['firstname']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("firstname");?> <?php echo $tNGs->displayFieldError("location", "firstname"); ?> </td>
</tr>
<tr>
<td class="KT_th"><label for="lastname">Lastname:</label></td>
<td><input type="text" name="lastname" id="lastname" value="<?php echo KT_escapeAttribute($row_rslocation['lastname']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("lastname");?> <?php echo $tNGs->displayFieldError("location", "lastname"); ?> </td>
</tr>
<tr>
<td class="KT_th"><label for="birthdate">Birthdate:</label></td>
<td><input type="text" name="birthdate" id="birthdate" value="<?php echo KT_formatDate($row_rslocation['birthdate']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("birthdate");?> <?php echo $tNGs->displayFieldError("location", "birthdate"); ?> </td>
</tr>
<tr>
<td class="KT_th"><label for="city">City:</label></td>
<td><input type="text" name="city" id="city" value="<?php echo KT_escapeAttribute($row_rslocation['city']); ?>" size="32" />
<?php echo $tNGs->displayFieldHint("city");?> <?php echo $tNGs->displayFieldError("location", "city"); ?> </td>
</tr>
<tr class="KT_buttons">
<td colspan="2"><label>
<input type="submit" name="browse" id="browse" value="Load csv" />
</label>
<input type="submit" name="KT_Insert1" id="KT_Insert1" value="Insert record" />
</td>
</tr>
</table>
</form>
<p> </p>
</body>
</html>
