随笔 - 78  文章 - 25  trackbacks - 0
<2015年7月>
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

常用链接

留言簿

随笔分类(75)

随笔档案(78)

相册

实用Links

我的Links

搜索

  •  

积分与排名

  • 积分 - 111761
  • 排名 - 519

最新评论

阅读排行榜

评论排行榜

php插入数据页面insertData.php
<html>
    <head>
        <title>向数据库中插入数据</title>
    </head>
    <body>
        <center>
            <form name="myForm" method="post" action="processInsertData.php">
                <table bgcolor="cyan">
                    <tr>
                        <td>学号</td>
                        <td><input type="text" name="txtId"  /></td>
                    </tr>
                    <tr>
                        <td>姓名</td>
                        <td><input type="text" name="txtName" /></td>
                    </tr>
                    <tr>
                        <td>年龄</td>
                        <td><input type="text" name="txtAge"></td>
                    </tr>
                    <tr>
                        <td>性别</td>
                        <td>
                            <select name="sSex">
                                <option value="male">male</option>
                                <option value="female">female</option>
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td>地址</td>
                        <td><input type="text" name="txtAddress"/></td>
                    </tr>
                    <tr>
                        <td colspan="2" align="center">
                            <input type="submit" name="submit" value="添加"/>
                            <input type="reset" name="reset" value="重置">
                        </td>
                    </tr>
                </table>
            </form>
        </center>
    </body>
</html>


处理数据插入页面processInsertData.php
<?php
    $link=mysql_connect("localhost","root","root");
    mysql_select_db("rorely");
    $id=$_POST['txtId']|null;
    $name=$_POST['txtName'];
    $age=$_POST['txtAge'];
    $sex=$_POST['sSex'];
    $address=$_POST['txtAddress'];

    $exec="insert into test values($id,'$name',$age,'$sex','$address')";
    $result=mysql_query($exec);
    if($result) echo "学生已添加到数据表中<br>";
    else echo "该学生没有添加进数据表,请重新输入。<br>";
    mysql_close();
?>
<a href="insertData.php">返回添加页面</a>

posted on 2009-07-01 14:03 期待明天 阅读(6008) 评论(7)  编辑  收藏 所属分类: PHP

FeedBack:
# re: php 向数据库表中插入数据 2010-01-20 13:34 嗷嗷嗷
大沙发的法定的  回复  更多评论
  
# re: php 向数据库表中插入数据[未登录] 2012-09-03 13:37 123
去问去问去问去问  回复  更多评论
  
# re: php 向数据库表中插入数据[未登录] 2012-09-03 13:38 123
@嗷嗷嗷
去问去问去问  回复  更多评论
  
# re: php 向数据库表中插入数据 2012-11-28 22:16 徐小松
请问为什么我从网页上输入数据后,$_post[]中的内容是空的呀?  回复  更多评论
  
# re: php 向数据库表中插入数据 2013-03-29 15:11 鹅鹅鹅鹅鹅鹅饿
热歌  回复  更多评论
  
# re: php 向数据库表中插入数据 2014-09-11 10:34 dgh
dthd  回复  更多评论
  
# re: php 向数yio据库表中插入数据 2015-07-16 22:30 yuio
uiol  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: