我正在创建一个简单的儿童及其生日数据库。
<?php
$chname1x = mysql_real_escape_string($_POST["chname1"]);
$chbdate1x = mysql_real_escape_string($_POST["chbdate1"]);
$chname2x = mysql_real_escape_string($_POST["chname2"]);
$chbdate2x = mysql_real_escape_string($_POST["chbdate2"]);
$chname3x = mysql_real_escape_string($_POST["chname3"]);
$chbdate3x = mysql_real_escape_string($_POST["chbdate3"]);
$chname4x = mysql_real_escape_string($_POST["chname4"]);
$chbdate4x = mysql_real_escape_string($_POST["chbdate4"]);
$chname5x = mysql_real_escape_string($_POST["chname5"]);
$chbdate5x = mysql_real_escape_string($_POST["chbdate5"]);
$dbhost='localhost';
$dbuser='root';
$dbpass='';
$conn=mysql_connect($dbhost,$dbuser,$dbpass) or die ('Could not connect to mysql');
$dbname='onlinepdsdb';
mysql_select_db($dbname);
if ($_POST['submitbutton'])
{
$query="INSERT INTO children (chname1,chbdate1,chname2,chbdate2,chname3,chbdate3,chname4,chbdate4,chname5,chbdate5) VALUES ('$chname1x', '$chbdate1x','$chname2x', '$chbdate2x','$chname3x', '$chbdate3x','$chname4x', '$chbdate4x','$chname5x', '$chbdate5x')";
mysql_query($query) or die (mysql_error());
echo "The user $uid has been succesfully registered.";
echo $query;
echo $uid;
}
<center>
<form method='POST' action='formchildren.php'>
<table border='3' style='width:700px'>
<tr bgcolor='#3399FF'>
<td colspan='2' class='head2' height='20'>NAME OF CHILD (Write full name and list all)</td>
<td colspan='3' class='head2' height='20'>DATE OF BIRTH (mm/dd/yyyy)</td>
</tr>
<tr>
<td class='numbering'>1.</td>
<td style='text-align:center;'>
<input type='text' name='chname1' size='45' maxlength='200'>
</td>
<td style='text-align:center;'>
<input type='date' name='chbdate1' size='45' maxlength='50'>
</td>
</tr>
<tr>
<td colspan=6 class='step' height='10'></td>
</tr>
<tr>
<td class='numbering'>2.</td>
<td style='text-align:center;'>
<input type='text' name='chname2' size='45' maxlength='200'>
</td>
<td style='text-align:center;'>
<input type='date' name='chbdate2' size='45' maxlength='50'>
</td>
</tr>
<tr>
<td colspan=6 class='step' height='10'></td>
</tr>
<tr>
<td class='numbering'>3.</td>
<td style='text-align:center;'>
<input type='text' name='chname3' size='45' maxlength='200'>
</td>
<td style='text-align:center;'>
<input type='date' name='chbdate3' size='45' maxlength='50'>
</td>
</tr>
<tr>
<td colspan=6 class='step' height='10'></td>
</tr>
<tr>
<td class='numbering'>4.</td>
<td style='text-align:center;'>
<input type='text' name='chname4' size='45' maxlength='200'>
</td>
<td style='text-align:center;'>
<input type='date' name='chbdate4' size='45' maxlength='50'>
</td>
</tr>
<tr>
<td colspan=6 class='step' height='10'></td>
</tr>
<tr>
<td class='numbering'>5.</td>
<td style='text-align:center;'>
<input type='text' name='chname5' size='45' maxlength='200'>
</td>
<td style='text-align:center;'>
<input type='date' name='chbdate5' size='45' maxlength='50'>
</td>
</tr>
<tr><input type='SUBMIT' name='submitbutton'></tr>
</table>
</form>
我在这里创建了 5 行,但如果孩子超过 5 行,则没有更多行。我想放置一个链接/按钮,如果单击它将在表和 mysql 中添加一行,但我不知道如何。