当我输入行数和列数时,我创建了一个表单,然后将生成行数和列数表我想将输入该表的值保存到数据库中。请任何人都可以帮助我.. 我的 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);
}
if(isset($_POST['submit']))
{
echo "<table border='1' align='center'>";
for($iii = 0;$iii <$_POST['column'];$iii++)
{
echo "<tr>".$jjj."</tr>";
for($jjj = 0; $jjj <$_POST['rows'];$jjj++) //loop for display no. of rows.
{
echo "<td>" ."<input type=\"text\" name='$iii'>"."</td>";
}
}
echo "</table>";
echo"<form name=\"aa\" method=\"post\">";
echo "<input type=\"submit\" name=\"save\" value=\"save\">";
echo "</form>";
}
$TestName = $_POST['testname'];
$Result = $_POST['result'];
$Unit = $_POST['unit'];
$NormalRange = $_POST['NormalRange'];
if(isset($_POST['save']))
{
$InsertQuery = "INSERT INTO rct(testname,result,unit,NormalRange) VALUES('$TestName','$Result','$Unit','$NormalRange')";
$oMysqli= getConnection();
$oMysqli->query($InsertQuery);
print_r($InsertQuery);exit();
while($Row = $InsertQuery->fetch_array())
{
$TestName = $Row['testname'];
$Result = $Row['result'];
$Unit = $Row['unit'];
$NormalRange = $Row['NormalRange'];
}
}
?>
<html>
<head>
<title>Rct</title>
</head>
<body>
<form name='abc' method="post">
<label for='Table'>Define Table</label>
<label for='rows'>Row</label>
<input type="text" name="column"></input>
<label for='column'>Column</label>
<input type="text" name="rows"></input>
<input type="submit" name="submit" value="submit" onclick="aaa()">
</form>
</body>
</html>