doutangtan6386 2012-06-06 06:49
浏览 42
已采纳

使用面向对象编程概念进行php表单处理的问题[关闭]

I am very new to PHP . I was asked to create a very simple form in PHP using OOPS . I managed to create a single page form with 2 text fields (name and ID) but the issue I am facing now is that when user clicks on submit button only the name gets stored in the database but not the ID . Could you please help me out in this . Below is the sample code Thank You in advance

PERSON.PHP

<?php
class person
{
    var $id;
    var $name;
    function set_id($new_id)
    {
        $this->id=$new_id;
    }

    function get_id()
    {
        return $this->id;
    }

    function set_name($new_name)
    {
        $this->name=$new_name;
    }

    function get_name()
    {
        return $this->name;
    }
}
?>

DBINPUT.PHP

 <?php
 include 'person.php';
 ?>
 <html>
 <body>
 <form action="dbinsert.php" method="post">
  NAME<input type="text" name="name" >/
  ID<input type="text" name="ID" />
  <input type="submit" value="submit">
  </form>
  </html>
    </body>

DBINSERT.PHP

 <?php
    include("person.php");
    $con = mysql_connect("localhost", "cgiadmin", "cgi");
    if (!$con)
    {
        die("couldn't connect ".mysql_error());
    }
    mysql_select_db("oops", $con);

    $person = new person;
    $person->set_name($_POST['name']);

    $person1 = new person;
    $person1->set_id($_POST['id']);


    $sql="INSERT INTO smallprogramusingoops (NAME ,ID ) VALUES ('".$person->get_name()."','".$person1->get_id()."')";
    if (!mysql_query($sql, $con))
    {
    die('Error in inserting '.mysql_error());
    }

    ?>

Could you please rectify my mistake ?

  • 写回答

2条回答 默认 最新

  • dream12001 2012-06-06 06:56
    关注

    The name attribute of your "id" field is in Block letters, while, when you access it via dbinsert.php, you use "id" instead of "ID".. Variables/indexes are case sensitive.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路