我在该表单中创建了一个表单,其中包含一个文本框和一个添加另一个按钮和保存按钮,在单击添加另一个按钮的事件时会生成新的文本框,但是当我单击保存按钮时,新生成的文本框值无法保存到数据库中,请任何人可以指导我
这是我的代码:
<?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); //create connection object.
return($oMysqli);
}
if(isset($_POST['submit']))
{
$TestParameters = $_POST['testparameters'];
$InsertQuery = "INSERT INTO test_table VALUES('$TestParameters')";
$oMysqli=getConnection();
$oMysqli->query($InsertQuery);
//print_r($InsertQuery);exit();
if(!$InsertQuery)
{
die('Could not enter data:' . mysql_error());
}
}
?>
<html>
<head>
<title>TestData</title>
<script type="text/javascript">
function create_row()
{
var newtr=document.createElement("tr");
var newtd=document.createElement("td");
var output="<input type=\"text\" name=\"testparameters\">";
newtd.innerHTML=output;
newtr.appendChild(newtd);
document.getElementById("table1body").appendChild(newtr);
}
</script>
</head>
<body>
<form name="testdetails" method="post" target="_self" action="<?php $_PHP_SELF ?>">
<label for="Testparameter">Testparameter</label>
<input type="text" name="testparameters"></input>
<table id="table1body">
<tr>
<td><input type="button" name="button" value="Add Test Parameter" onclick="create_row()">
</tr>
</table>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>