我正在创建一个简单的儿童数据库及其生日。
<?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中添加一行,但我不知道如何。
答案 0 :(得分:0)
您可以使用jQuery
.append()
这是来源jQuery Append
使用追加:
例如点击一个按钮,你可以追加另一个textbox and dropdown list
在你身上如何做到这一点......这只是一个提示。 ;)
这里的例子:
答案 1 :(得分:0)
您的表单的提交按钮字段是向后的。切换类型&amp;名称。 类型应为“submit”,名称为“submitbutton”
例如
<input type='submit' name='submitbutton'>
这样,HTML将是正确的,您的PHP代码将寻找正确的字段名称:
if ($_POST['submitbutton'])