[求助] 关于数据插入数据库的问题
补充资料
我想把表中输入的数据插入数据库中 
---------------------------------------------------------------------------------------
<?php
include_once("./common_class/class.admin.php");
$objAdmin = new cAdmin();
$hrusername = $_POST['hrusername'];
$hrname= $_POST['hrname'];
$hrdept_id=$_POST['hrdept_id'];$hrResult = $objAdmin->addnewstaff($hrusername, $hrname, $hrdept_id);
$hrcheck = "的信息如下";
echo $hrResult;
echo  $hrusername.$hrcheck."<br/>";
echo "姓名:". $hrusername."<br/>";
echo "用户名:". $hrname."<br/>";
echo "部门:". $hrdept_id."<br/>";
?><style type="text/css">
<!--
.STYLE1 {font-family: "微软雅黑"}
.STYLE2 {
font-size: 18px;
font-weight: bold;
}
-->
</style>
<tr>
  <td colspan="2" align="center">   
    <p> </p>
    <p> </p>
    <p> </p>
    <p> </p>
    <div align="center">
  <td colspan="4" align="center"><p><span class="STYLE15 STYLE1 STYLE2">操作成功!</span></p>
    <p><span class="STYLE15"><br/>
      <br/>
    </span></p></td>
      <div align="center">
        <button>
          <span class="STYLE1">返回首页</span></button>
        </div>
</tr>-------------------------------------------------------------------------------------------------------------------------------------------另外在/class.admin.php/插入数据库的语句为function addnewstaff($hrusername, $hrname, $hrdept_id)
{    
        mysql_select_db($this->DBName, $this->DBHandle);
      
   $sql = " INSERT into user ('username', 'name', 'dept_id') values ('$hrusername', '$hrname', '$hrdept_id')" ;
            
   if ($qry = mysql_query($sql, $this->DBHandle))
   {
   return true;
      }
    
   else 
   {
   $this->ErrorNo = 0002010601;
   $this->ErrorMsg = "修改数据失败:SQL: -- $sql -- Mysql Error : " . mysql_error($this->DBHandle);
   return false;
         }
  }
------------------------------------------------------------------------------------------------------------------------------------------但是运行以后 数据无法插入数据库 我知道在替换的时候有str_replace() 那我插入的时候应该用什么语句 我是新手来着 希望大家能帮我解答一下 谢谢了各位

解决方案 »

  1.   

    $sql = " INSERT into user ('username', 'name', 'dept_id') values ('$hrusername', '$hrname', '$hrdept_id')" ; SQL语句有错误
    1:字段名是不需要加''的
    2:表名用user好象不行,user是保留字
      

  2.   


    我感觉好象根本没有调用到我写在class.php里面的function addnewstaff 
    不知道下面这句话是不是写错了$hrResult = $objAdmin->addnewstaff($hrusername, $hrname, $hrdept_id); 
    我知道在替换的时候有str_replace() 那我插入的时候应该用什么语句
      

  3.   

    我建的表是 是common 里面的两张表 一张department 一张是 user
      

  4.   

    function addnewstaff($hrusername, $hrname, $hrdept_id) 
    {    
            mysql_select_db($this->DBName, $this->DBHandle); 
          
      $sql = " INSERT 
    into user ('username', 'name', 'dept_id') values ('$hrusername', '$hrname', '$hrdept_id')" ; 
    你的sql语句写的有问题
    你可以在$sql=.....的后面
    用echo $sql;exit;看看你的sql语句输出的是什么  $sql = " INSERT 
    into user ('username', 'name', 'dept_id') values ('$hrusername', '$hrname', '$hrdept_id')" ; 
    同样字段名不能有''单引号,你可以用tab上面的``这个符号将字段名包含,修改一下再试试
      

  5.   

    $sql = " INSERT into user (username, name, dept_id) values ('".$hrusername."', '".$hrname."', '".$hrdept_id."')" ;