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条)

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line