Re: Posting values of dynamically generated text fields at a time

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I couldn't able understand exactly what your requirement is. I have attached 
a php page below, just see whether this helps...

This one generates text fields dynamically in a page and then onSubmit it 
takes the values to DB process...

Thanks,
saravana 

<?php
$postflag = false;
if(isset($_POST['Submit'])) {
$postflag = true;
//Store the values of Text Fields in an Array from global variable $_POST
//{ ... }
print_r($_POST);

$host = "localhost"; //database location
$user = "root"; //database username
$pass = ""; //database password
$db_name = "sample"; //database name

//database connection
$link = mysql_connect($host, $user, $pass);
if (!$link){
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $link);

//Query to insert the data
$query = "INSERT INTO sampledb1 ..."; //Insert query including all the values stored from $_POST
mysql_query($query, $link);
mysql_close($link);
}
?>
<html>
<head>
<title>DB Sample</title>
<script language="javascript" type="text/javascript">
function addFieldsx() {
document.getElementById('tbl').style.display = 'none';
var n = document.getElementById('x').value;
var frm = document.forms[0];

var dynamicTable = document.createElement("table");
dynamicTable.width = 500;
dynamicTable.border = 0;
dynamicTable.cellpadding = 5;
dynamicTable.cellspacing = 0;
dynamicTable.name = "tbl2";
dynamicTable.id = "tbl2";

for(var i = 0; i < n; i++) {
row = dynamicTable.insertRow(i);
cell0 = row.insertCell(0);
cell0.width = 200;
cell0.align = "right";
cell0.innerHTML = "Text " + (i + 1);

cell1 = row.insertCell(1);
input = document.createElement("input");
input.type = "text"; // set the input's type to a textbox
input.name =  "txt" + (i + 1); // the elements name is "txtArea51"
cell1.appendChild(input);
}

row = dynamicTable.insertRow(i);
cell0 = row.insertCell(0);
cell0.width = 200;
cell0.align = "right";
cell0.innerHTML = "&nbsp;";

cell1 = row.insertCell(1);
input = document.createElement("input");
input.type = "submit"; // set the input's type to a textbox
input.name =  "Submit"; // the elements name is "txtArea51"
cell1.appendChild(input);

frm.appendChild(dynamicTable)

}
</script>
</head>
<body> 
<?PHP
if (!$postflag) {
?> 
<form name="dbfrm" id="dbfrm" action="" method="post"> 
  <table width="500" border="0" cellspacing="5" cellpadding="0" id="tbl"> 
    <tr> 
      <td width="200">&nbsp;</td> 
      <td>&nbsp;</td> 
    </tr> 
    <tr> 
      <td width="200" align="right">No of Fields: </td> 
      <td><input type="textfield" name="x" id="x"/></td> 
    </tr> 
    <tr> 
      <td width="200">&nbsp;</td> 
      <td><input type="button" name="Add" value="Add Fields" onClick="addFieldsx()"></td> 
    </tr> 
  </table> 
</form> 
<?php } ?> 
</body>
</HTML>



----- Original Message ----- 
From: "Ashley Sheridan" <ash@xxxxxxxxxxxxxxxxxxxx>
To: <saravanan.murugesan@xxxxxxxxx>
Cc: "Amit Bobade" <amit@xxxxxxxxx>; <php-general@xxxxxxxxxxxxx>
Sent: Wednesday, July 14, 2010 2:00 PM
Subject: Re:  Posting values of dynamically generated text fields at a time


> On Wed, 2010-07-14 at 12:08 +0530, Saravanan Murugesan wrote:
> 
>> > Hi is anybody there to help me out on this?????
>> >
>> >>
>> >> Hi all,
>> >> I am new to PHP and JS.
>> >>
>> >> I am adding new text fields using javascript and I have to save the
>> >> values
>> >> of these fields in database in single row. So, how should I post these
>> >> values? So that I can save them in the db.
>> >>
>> >> Additional Info: There are 6 text fields in the row. I have to post the
>> >> information of all the fields collectively.
>> >>
>> >> So, please suggest me a way.........
>> >> --
>> >> Thanks and Regards,
>> >> Amit
>> >>
>> >>
>> >
>> >
>> > --
>> > Thanks and Regards,
>> > Amit
>> > eArth Solutions Pvt. Ltd
>> >
>> 
>> Hi,
>> 
>> this would help you,
>> http://www.w3schools.com/PHP/php_mysql_insert.asp
>> 
>> Thanks,
>> Saravana
>> 
>> 
>> ===========================================================
>> ***Disclaimer***
>> 
>> 
>> This email, and any attachments ("this email"), is confidential. If you are not the addressee
>> please tell the sender immediately, and destroy this email without using, sending or storing
>> it. Any opinions, express or implied, in this email, are those of the sender, and are not
>> necessarily approved by Hurix Systems. Except as expressly stated, this e-mail should not be
>> regarded as an offer, solicitation, recommendation or agreement to buy or sell products or
>> services, or to enter into any contract. E-mail transmissions are not secure and may suffer
>> errors, viruses, delay, interception and amendment. Hurix Systems does not accept liability
>> for damage caused by any of the foregoing.
>> 
>> HURIX SYSTEMS MAY MONITOR ALL INCOMING AND OUTGOING MAILS
>> ============================================================
>> 
> 
> 
> Erm, that's not even remotely an answer to the OPs question...
> 
> Thanks,
> Ash
> http://www.ashleysheridan.co.uk
> 
> 
>

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux