0

好吧,现在,我创建了一个表单,就是这样:

<html>
<body bgcolor="lightblue">


<form align="center" action="connect2.php"  method="post" style="bgcolor:red">


        <div style="margin-left:433px" >
        Registration No.: <input type="text" name="reg" /><br />
        </div>
        </br>
        Name: <input type="text" name="name" size="50" style="margin-left:7px" />  
        <span style="margin-left:6px">
        Date of Birth: <input type="text" name="birth" size="30" /></br>
        </span>
            <div style="margin-left:12px">
                Age: <input type="text" name="age" size="15" style="margin-left:7px" />
                <span style="margin-left:167px">
                Class at August 2012 <input type="text" name="class" size="30" />
                </span>
            </div>
        School: <input type="text" name="school" size="102" style="margin-left:5px" />
        </br></br>
        Father's Name: <input type="text" name="father" size="94" style="margin-left:5px" /> </br>
        Father's Occupation: <input type="text" name="focc" size="89" />
        </br></br>
        Mother's Name:<input type="text" name="mother" size="94" style="margin-left:3px" /> </br>
        Mother's Occupation: <input type="text" name="mocc" size="88" />
        </br></br>

        <center>

            <table bgcolor="pink" width="95" height="100"style="margin-left:0px; margin-top:5px" border="0">
                <tr>
                    <td colspan="3">
                    Siblings, if any:
                    </td>
                </tr>
                <tr align="center"style="font-weight:bold">
                    <td width="5"></td>
                    <td width="20">Name</td>
                    <td width="50">Age</td>
                    <td width="20">School</td>
                </tr>
                <tr align="right">
                    <td>1.</td>
                    <td align="center"><input type="text" name="ssname" size="44" /></td>
                    <td align="center"><input type="text" name="sage1" size="5" /></td>
                    <td align="center"><input type="text" name="sschool1" size="44" /></td>
                </tr>
                <tr align="right">
                    <td>2.</td>
                    <td align="center"><input type="text" name="sname2" size="44" /></td>
                    <td align="center"><input type="text" name="sage2" size="5" /></td>
                    <td align="center"><input type="text" name="sschool2" size="44" /></td>
                </tr>
                <tr align="right">
                    <td >3.</td>
                    <td align="center"><input type="text" name="sname3" size="44" /></td>
                    <td align="center"><input type="text" name="sage3" size="5" /></td>
                    <td align="center"><input type="text" name="sschool3" size="44" /></td>
                </tr>
            </table>
        </center>
        </br>
        Address: <input type="text" name="address" size="101" /> </br>
        <p align="left" style="margin-left:271px">
        Phone Number: <input type="text" name="phone" size="20" /> </br>
        Cell Number (Mother/Father): <input type="text" name="cp" size="20" /></br>
        Email (Mother/Father): <input type="text" name="email" size="28"/>
        </p>
        <input type="Submit" name="submit" value="submit" />

        </form>




</body>
</html>

然后这是我的 php 代码:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<body> 
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("sy_database", $con);

$sq$sql="INSERT INTO sy_form (reg_no, name, birth, age, sclass, school, fname, focc, mname, mocc, address, phone, cp, email)
VALUES('$_POST[reg]','$_POST[name]','$_POST[birth]','$_POST[age]','$_POST[class]','$_POST[school]','$_POST[fname]','$_POST[focc]','$_POST[mname]','$_POST[mocc]','$_POST[address]','$_POST[phone]','$_POST[cp]','$_POST[email]'),
INSERT INTO siblings(sname,sage,sschool) values('$_POST[ssname]','$_POST[sage1]','$_POST[sschool1]')";


if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }

echo "1 record added";

mysql_close($con);
?>
</body> 
</html>

我需要从该单一表单将数据插入到两个表中。第一张桌子是给想要注册的人的,第二张桌子是给那个人的兄弟姐妹的。

为什么AGE不会出现?一月的课程也没有出现。手机号码永远是2147483647?

天哪,我被毁了!有人可以帮我吗?我真的很想学习。:(

4

1 回答 1

1

啊,你不能像那样合并查询。尝试关注

$sql1="INSERT INTO sy_form (reg_no, name, birth, age, sclass, school, fname, focc, mname, mocc, address, phone, cp, email)".
"VALUES('$_POST[reg]','$_POST[name]','$_POST[birth]','$_POST[age]','$_POST[class]','$_POST[school]','$_POST[fname]','$_POST[focc]','$_POST[mname]','$_POST[mocc]','$_POST[address]','$_POST[phone]','$_POST[cp]','$_POST[email]')";

$sql2="INSERT INTO  siblings(sname,sage,sschool)values('$_POST[ssname]','$_POST[sage1]','$_POST[sschool1]')";

if (!mysql_query($sql1,$con))
{
    die('Error: ' . mysql_error());
}
if (!mysql_query($sql2,$con))
{
    die('Error: ' . mysql_error());
}

那么这才刚刚开始,让你的程序运行。有很多东西要学。

于 2012-09-03T14:24:06.287 回答