我创建了一个表单,其中包含测试代码、测试名称、测试参数是文本框和仪器代码是下拉列表并且还包含单击添加另一个按钮为新测试参数添加另一个按钮文本框和新仪器的下拉列表将生成代码我想保存新生成的测试参数文本框数据和新生成的单个测试代码的仪器代码下拉列表数据的数据..
我已经创建但它无法保存动态生成的新的多个文本框数据和生成的仪器代码下拉列表数据请指导我。这是我的PHP代码:
<?php
global $Hostname;
global $Username;
global $Password;
global $Database_name;
function getConnection()
{
$Hostname = "localhost";
$Username ="root";
$Password ="";
$Database_name="labdata";
$oMysqli = new mysqli($Hostname,$Username,$Password,$Database_name);
return($oMysqli);
}
include_once "dTestCreation.php";
if(isset($_POST['submit']))
{
$Testcode = $_POST['testcode'];
$TestName = $_POST['testname'];
$Testparameter = $_POST['testparameters'];
$Instrumentcode = $_POST['instrument_code'];
$InsertQuery = "INSERT INTO demo_test(testcode,testname) VALUES('$Testcode','$TestName')"; //query for insert data into table
$oMysqli=getConnection(); //establish connection
$oMysqli->query($InsertQuery);
$InsertQuery1 = "INSERT INTO test_table(testcode,testparameters,instrument_code) VALUES('$Testcode','$Testparameter','$Instrumentcode')";
$oMysqli=getConnection(); //establish connection
$oMysqli->query($InsertQuery1);
}
?>
<html>
<head>
<title>TestData</title>
<script type="text/javascript">
function create_row() //create function create_row
{
var newtr=document.createElement("tr"); //variable for tr
var newtd=document.createElement("td"); //variable for td
var newtd1=document.createElement("td"); //variable f
var output="<input type=\"text\" name=\"testparameters[]\">";
/*var output1="<select name=\"instrument_name\"><option value='$tResult[$kkk]'>tResult[$kkk]</option></select>";*/
var output1="<select id=\"instrument_code\"><?php include_once "dTestCreation.php"; //include file dTestCreation.php
$tResult = getIname();
for($kkk=0;$kkk<count($tResult);$kkk++)
{
echo "<option value=".$tResult[$kkk].">".$tResult[$kkk]."</option>";
}//display values of instrument into list.
?></select>";
newtd.innerHTML=output; //display first td
newtd1.innerHTML=output1; //display second td
newtr.appendChild(newtd); //increment no of rows.
newtr.appendChild(newtd1);
document.getElementById("table1body").appendChild(newtr);
}
</script>
</head>
<body>
<form name="testdetails" method="post" target="_self" action="<?php $_PHP_SELF ?>">
<label for='Testcode'>Testcode</label>
<input type="text" name="testcode"></input>
<label for='TestName'>TestName</label>
<input type="text" name="testname"></input><br></br>
<label for='Testparameter'>Testparameter</label>
<input type="text" name="testparameters"></input>
<label for='Instrumentcode'>Instrumentcode</label>
<select name="instrument_code">
<?php
$tResult = getIname(); for($kkk=0;$kkk<count($tResult);$kkk++) //loop for incremenet code hereted value display in listbox.
{
echo "<option value=".$tResult[$kkk].">".$tResult[$kkk]."</option>";
}`enter code here`
?>
</select>
<table>
<tbody id="table1body">
<tr>
<!--<td><input type="textfield" name="testparameters"></td>-->
<td> <input type="button" name="button" value="Add Test Parameter" onclick="create_row()"> <!--call function create_row() for onclik add new row-->
</tr>
</tbody>
</table>
<input type="submit" name="submit" value="submit"></input>
</form>
</body>
</html>