值作为null发送到数据库

时间:2014-05-09 07:20:01

标签: php mysql database

在我的注册表格中,我已经从数据库中填写了3个组合框。但是当我填写表单并单击提交按钮时,组合框的值在数据库表中为空。 这是我的PHP代码,用于从表单中获取值:

class insrtEmpDet{
    public function insrtDet(){
        $connection=new connectdb();
        $con=$connection->getCon();


        $pfno =$_POST['pfno'];
        $fname =$_POST['fname'];
        $lname =$_POST['lname'];
        $address =$_POST['address'];
        $tel = $_POST['tel'];
        $email =$_POST['email'];
        $pwd =$_POST['pwd'];
        $cpwd= $_POST['confirmpwd'];
        $dep =$_POST['department'];
        $des =$_POST['designation'];
        $sec =$_POST['sec'];

        $sqlq="INSERT INTO employee(pfno,fname,lname,address,tel,email,pwd,confirmpwd,Des_id,sec_id)VALUES('$pfno','$fname','$lname','$address','$tel','$email','$pwd','$cpwd',(select Des_id from designation where detail='$des'),(select sec_id from section where section.detail='$sec'))";


        if (!mysqli_query($con,$sqlq)) {
            die('<br> Insertion Error: ' . mysqli_error($con));
        }
        echo "<br> 1 record added.";

        mysqli_close($con);

    }
}
$emp=new insrtEmpDet();
$obj=$emp->insrtDet();

这是我加载组合框的功能:

public function loadCombo(){
    $connection=new connectdb();
    $con=$connection->getCon();
    $query = "SELECT * FROM department";
    $result = mysqli_query($con,$query) or die(mysqli_error());

    while($row=mysqli_fetch_assoc($result)){ 
        echo "<option value='".$row["dno"]."'>".$row["detail"]."</option>";
    }
}
public function loadSection(){
    $connection=new connectdb();
    $con=$connection->getCon();
    $query = "SELECT * FROM section";
    $result = mysqli_query($con,$query) or die(mysqli_error());

    while($row=mysqli_fetch_assoc($result)){ 
        echo "<option value='".$row["sec_id"]."'>".$row["detail"]."</option>";
    }

}
public function loadDes(){
    $connection=new connectdb();
    $con=$connection->getCon();
    $query = "SELECT * FROM designation";
    $result = mysqli_query($con,$query) or die(mysqli_error());

    while($row=mysqli_fetch_assoc($result)){ 
        echo "<option value='".$row["Des_id"]."'>".$row["detail"]."</option>";  
    }
}

sec_idDes_id应保存在员工表中。但是当我提交时,这两列是空的。请帮我解决这个问题。

0 个答案:

没有答案