RednBlack
RednBlack

Reputation: 102

php mysql insert in table textarea lines

I`am using this form to import keys to database one by one. How to make the form to import keys from textarea (as lines) and to save them (as line) on table.

This is my code Iam using:

HTML CODE:

<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Product Paket:</td>
      <td><select name="produktid">
        <?php
do {  
?>
        <option value="<?php echo $row_Paketa['paketaid']?>"><?php echo $row_Paketa['emripaketa']?></option>
        <?php
} while ($row_Paketa = mysql_fetch_assoc($Paketa));
  $rows = mysql_num_rows($Paketa);
  if($rows > 0) {
      mysql_data_seek($Paketa, 0);
      $row_Paketa = mysql_fetch_assoc($Paketa);
  }
?>
      </select></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Serial Number:</td>
      <td><textarea cols="45" rows="5" name="seriali" /></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Voucher Number:</td>
      <td><textarea cols="45" rows="5" name="kodiabonimit" /></textarea></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Insert record" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>

PHP CODE:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
     $insertSQL = sprintf("INSERT INTO products (pid, produktid, seriali, kodiabonimit, data) VALUES (%s, %s, %s, %s, NOW())",
                       GetSQLValueString('', "int"),
                       GetSQLValueString($_POST['produktid'], "int"),
                       GetSQLValueString($_POST['seriali'], "text"),
                       GetSQLValueString($_POST['kodiabonimit'], "text")
                       );
  mysql_select_db($database, $ksam);
  $Result1 = mysql_query($insertSQL, $ksam) or die(mysql_error());
}

Upvotes: 0

Views: 1264

Answers (1)

RednBlack
RednBlack

Reputation: 102

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$codi  = $_POST['kodiabonimit'];    
$serial = $_POST['seriali'];


$text = $codi;
$text1 = $serial;



$itemserial = explode("\n", $serial);
$itemcodi = explode("\n", $codi);

foreach(array_combine($itemcodi, $itemserial) as $text => $text1)
{
//code to insert into database

Upvotes: 2

Related Questions