Jump to content

multi-generated fields. problem to store them in db


illus

Recommended Posts

i have the script to generate boxes. now how i will pass the values of the multi-generated boxes to the "action.php" ? i don't have any idea on how to implement this...

 

<html>
<head>
<script type="text/javascript">
trId=0;
function addElement(obj) {
myTable=document.getElementById("mailTable").getElementsByTagName('tbody')[0];
myNewTR = document.createElement("tr");
myNewTD1 = document.createElement("td");
myNewTD2 = document.createElement("td");
myNewTD3 = document.createElement("td");
myTextField = document.createElement("input");
trId++;
myNewTR.id=trId;

myTextField.type="text";
myTextField.size="50";
myTextField.maxlength="50";
myNewTD1.appendChild(myTextField);

myMinusPicture = document.createElement("img");
myMinusPicture.src="minus.gif";
myMinusPicture.onclick=function(){deleteElement(this);};
myNewTD2.appendChild(myMinusPicture);

myPlusPicture = document.createElement("img");
myPlusPicture.src="plus.gif";
myPlusPicture.onclick=function(){addElement(this);};
myNewTD3.appendChild(myPlusPicture);

myNewTR.appendChild(myNewTD1);
myNewTR.appendChild(myNewTD2);
myNewTR.appendChild(myNewTD3);

var pare = obj.parentNode.parentNode;
var par_ID = pare.id;
var next = document.getElementById(par_ID).nextSibling;
myTable.insertBefore(myNewTR,next);
return;
}


function deleteElement(myobj) {
myTable=document.getElementById("mailTable").getElementsByTagName('tbody')[0];
var toDelete = myobj.parentNode.parentNode;
myTable.removeChild(toDelete);
return;
}

</script>
</head>
<body>
<form id="form1" name="form1" method="post" action="action.php">
  
  <table width="500" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td width="193">Name</td>
      <td width="99"> </td>
      <td width="208"><input name="rqrName" type="text" id="rqrName"></td>
    </tr>
    <tr>
      <td>Password</td>
      <td> </td>
      <td><input name="rqrPassword" type="password" id="rqrPassword"></td>
    </tr>
    <tr>
      <td colspan="3"> </td>
    </tr>
    <tr>
      <td colspan="3"><table width="330" border="0" cellspacing="0" cellpadding="0" id="mailTable">
        <tr id="0">
          <td width="300"><input name="textfield" type="text" size="50" maxlength="50" /></td>
          <td width="15"> </td>
          <td width="15"><img src="plus.gif" width="13" height="13" onClick="addElement(this)"></td>
        </tr>
        <tr id="last"></tr>
      </table></td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
      <td> </td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
      <td><input type="submit" name="Submit" value="Submit"></td>
    </tr>
  </table>
</form>
</body>
</html>

 

action.php

<?php
require_once('connectToDatabase.php');

if(isset($_POST['Submit'])) //input name
{
$name= $_POST['rqrName'];
$password= $_POST['rqrPassword'];

$query1 = "INSERT INTO tblUsers (userName,password) VALUES ('$userName', MD5('$password'))";
mysql_query($query1) or die('Error ,query failed');

// how to get values and enter a new row for each of them ??????
$query2 = "INSERT INTO tblUserMultiFields (userName,telephone) VALUES ('$userName','$telephone')";
mysql_query($query2) or die('Error ,query failed');
}
?>

 

thanks

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.