-1

我正在创建一个简单的儿童及其生日数据库。

在这里提琴

<?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 中添加一行,但我不知道如何。

4

2 回答 2

0

您表单的提交按钮字段是向后的。切换类型和名称。类型应为“提交”,名称应为“提交按钮”

例如

<input type='submit' name='submitbutton'>

这样,HTML 将是正确的,您的 PHP 代码将寻找正确的字段名称:

if ($_POST['submitbutton'])
于 2013-05-14T07:49:17.593 回答
0

您可以使用jQuery .append()

这里是源jQuery Append

使用附加:例如,通过单击一个按钮,您可以附加另一个textbox and dropdown list 它在您身上,您可以如何做到这一点。这只是一个提示。;)

这里的例子:

http://jsfiddle.net/lian23/Sz73b/

于 2013-05-14T06:56:58.577 回答