如下附input.html,insert_product.php与数据库表product.sql
input.html
---------------------------------------------------------------------------
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>input product information</title>
<style type="text/css">
<!--
.STYLE1 {color: #FF0000}
-->
</style>
</head><body>
<h1 align="center">AVIDITE TRADING Co ., Ltd.</h1>
<hr align="center" />
<h2 align="center">product data input   (*for must fill in )</h2>
<form action="insert_product.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <table width="891" border="1" align="center" cellpadding="5" bgcolor="#EEEEEE">
    <tr>
      <td width="130"><div align="right">ID</div></td>
      <td colspan="3"><input name="id" type="text" id="id" />
        <span class="STYLE1">*</span></td>
    </tr>
    <tr>
      <td><div align="right">CATEGORY</div></td>
      <td colspan="3">
  <select name="categoryid" id="categoryid">
        <option value="1" >Fires </option>
        <option value="2">Furniture</option>
        <option value="3">Autobike</option>
      </select>
      <span class="STYLE1"> *</span></td>
    </tr>
    <tr>
      <td><div align="right">PRODUCT NAME </div></td>
      <td colspan="3"><input name="name" type="text" id="name" />
      <span class="STYLE1"> *</span></td>
    </tr>
    <tr>
      <td><div align="right">TYPE</div></td>
      <td colspan="3"><input name="type" type="text" id="type" /></td>
    </tr>
    <tr>
      <td><div align="right">ACM CODE </div></td>
      <td colspan="3"><input name="acm_code" type="text" id="acm_code" />
      <span class="STYLE1"> *</span></td>
    </tr>
    <tr>
      <td><div align="right">PRODUCT DESCRIPTION </div></td>
      <td colspan="3"><textarea name="description" id="description"></textarea></td>
    </tr>
    <tr>
      <td><div align="right">METERIAL</div></td>
      <td colspan="3"><input name="meterial" type="text" id="meterial" /></td>
    </tr>
    <tr>
      <td><div align="right">PACKAGING</div></td>
      <td colspan="3"><input name="packaging" type="text" id="packaging" /></td>
    </tr>
    <tr>
      <td><div align="right">QTY/CTN</div></td>
      <td colspan="3"><input name="qty" type="text" id="qty" /></td>
    </tr>
    <tr>
      <td><div align="right">MEASUREMENT</div></td>
      <td width="240">HEIGHT
      <input name="height" type="text" id="height" /></td>
      <td width="217">WIDTH
      <input name="width" type="text" id="width" /></td>
      <td width="254">LENGTH
      <input name="length" type="text" id="length" /></td>
    </tr>
    <tr>
      <td><div align="right">CBM/CTN</div></td>
      <td colspan="3"><input name="cbm" type="text" id="cbm" /></td>
    </tr>
    <tr>
      <td><div align="right">G.W./CTN</div></td>
      <td colspan="3"><input name="gw" type="text" id="gw" /></td>
    </tr>
    <tr>
      <td rowspan="2"><div align="right">PRICE</div></td>
      <td colspan="3">RMB
      <input name="price_rmb" type="text" id="price_rmb" /></td>
    </tr>
    <tr>
      <td colspan="3">USD
      <input name="price_usd" type="text" id="price_usd" /></td>
    </tr>
    <tr>
      <td><div align="right">NOTE</div></td>
      <td colspan="3"><textarea name="note" id="note"></textarea></td>
    </tr>
    <tr>
      <td><div align="right">PICTURE</div></td>
      <td colspan="3"><input name="picture" type="file" id="picture" /></td>
    </tr>
    <tr>
      <td><div align="right">SUBPRODUCT </div></td>
      <td colspan="3"><input name="sub" type="text" id="subproduct" value="0" />
       have sub product(1 for yes,0 for no)</td>
    </tr>
    <tr>
      <td><div align="right">IMPORT EXCEL DATA </div></td>
      <td colspan="3"><input name="import" type="file" id="import" /></td>
    </tr>
    <tr>
      <td colspan="4">&nbsp;</td>
    </tr>
    <tr>
      <td colspan="3"><div align="center">
        <input type="submit" name="submit" value="SUBMIT" />
      </div></td>
      <td><div align="center">
        <input type="reset" name="cancel" value="CANCEL" />
      </div></td>
    </tr>
  </table>
  <div align="left"></div>
</form>
</body></html>
------------------------------------------------------------------------------------

解决方案 »

  1.   

    insert.php
    ---------------------------------------------------------------------------------------
    <html>
    <head>
    <title>product information</title>
    </head>
    <body>
    <h1 align="center">AVIDITE TRADING Co ., Ltd.</h1>
    <hr align="center" />
    <?php//create short variable names
    $id=$_POST['id'];
    $categoryid=$_POST['categoryid'];
    $name=$_POST['name'];
    $type=$_POST['type'];
    $acm_code=$_POST['acm_code'];
    $description=$_POST['description'];
    $material=$_POST['meterial'];
    $packaging=$_POST['packaging'];
    $qty=$_POST['qty'];
    $height=$_POST['height'];
    $width=$_POST['width'];
    $length=$_POST['length'];
    $cbm=$_POST['cbm'];
    $gw=$_POST['gw'];
    $price_rmb=$_POST['price_rmb'];
    $price_usd=$_POST['price_usd'];
    $note=$_POST['note'];
    $picture=$_POST['picture'];
    $sub=$_POST['sub'];/*
    echo $id.'<br>';
    echo $categoryid.'<br>';
    echo $name.'<br>';
    echo $type.'<br>';
    echo $acm_code.'<br>';
    echo $description.'<br>';
    echo $material.'<br>';
    echo $packaging.'<br>';
    echo $qty.'<br>';
    echo $height.'<br>';
    /*
    echo $searchtype.'<br>';
    echo $searchtype.'<br>';
    echo $id.'<br>';
    echo $searchtype.'<br>';
    echo $searchtype.'<br>';/*
      if(!$id || !$categoryid || !$name || !$acm_code)
      {
         echo 'You have not entered all the required details.<br />'
              .'Please go back and try again.';
         exit;
      }
      
     if (!get_magic_quotes_gpc())
      {
        $isbn = addslashes($isbn);
        $author = addslashes($author);
        $title = addslashes($title);
        $price = doubleval($price);
      }
      */
     echo 'ok1';
      @ $db=new mysqli('localhost','root','165832','product');  if (mysqli_connect_errno()) 
      {
         echo 'Error: Could not connect to database.  Please try again later.';
         exit;
      }  $query = "insert into product values 
                ('".$id."', '".$categoryid."', '".$name."','".$type."', '".$acm_code."',
                '".$description."', '".$material."', '".$packaging."', '".$qty."','".$height."',
                '".$width."', '".$length."', '".$cbm."', '".$gw."',
                '".$price_rmb."', '".$price_usd."', '".$note."', '".$picture."','".$sub."')"; 
      
       $result = $db->query($query);
      if ($result)
          echo  $db->affected_rows.' product inserted into database.'; 
      
    ?><form action="insert_product.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
      <table width="891" border="1" align="center" cellpadding="5" bgcolor="#EEEEEE">
        <tr>
          <td width="130"><div align="right">ID</div></td>
          <td colspan="3"><?php echo $id;  ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">CATEGORY</div></td>
          <td colspan="3"><?php echo $categoryid;  ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">PRODUCT NAME </div></td>
          <td colspan="3"><?php echo $name;  ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">TYPE</div></td>
          <td colspan="3"><?php echo $type;  ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">ACM CODE </div></td>
          <td colspan="3"><?php echo $acm_code;  ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">PRODUCT DESCRIPTION </div></td>
          <td colspan="3"><?php echo $description;  ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">METERIAL</div></td>
          <td colspan="3"><?php echo $material;  ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">PACKAGING</div></td>
          <td colspan="3"><?php echo $packaging;  ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">QTY/CTN</div></td>
          <td colspan="3"><?php echo $qty; ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">MEASUREMENT</div></td>
          <td width="240">HEIGHT:      <?php echo  $height; ?>&nbsp;</td>
          <td width="217">WIDTH:      <?php echo  $width; ?>&nbsp;</td>
          <td width="254">LENGTH:      <?php echo  $length; ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">CBM/CTN</div></td>
          <td colspan="3"><?php echo  $cbm; ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">G.W./CTN</div></td>
          <td colspan="3"><?php echo $gw;  ?>&nbsp;</td>
        </tr>
        <tr>
          <td rowspan="2"><div align="right">PRICE</div></td>
          <td colspan="3">RMB:      <?php echo  $price_rmb; ?>&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3">USD:      <?php echo  $price_usd; ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">NOTE</div></td>
          <td colspan="3"><?php echo $note;  ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">PICTURE</div></td>
          <td colspan="3"><?php echo  $picture; ?>&nbsp;</td>
        </tr>
        <tr>
          <td><div align="right">SUBPRODUCT </div></td>
          <td colspan="3"><?php echo $sub;  ?>&nbsp;</td>
        </tr>
        <tr>
          <td colspan="4">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3"><div align="center">
            <input type="submit" name="submit" value="SUBMIT" />
          </div></td>
          <td><div align="center">
            <input type="reset" name="cancel" value="CANCEL" />
          </div></td>
        </tr>
      </table>
      <div align="left"></div>
    </form>
    <?php
      $db->close();
    ?></body>
    </html>
    ------------------------------------------------------------------------------------
      

  2.   

    product.sql
    ------------------------------------------------------------------------------------
    CREATE DATABASE product;
    USE productCREATE TABLE `product` (
      `id` int(11) NOT NULL auto_increment                                   COMMENT  '产品系统自动生成的唯一ID号',
      `categoryid` smallint(4) NOT NULL default '0'                          COMMENT  '产品目录ID',
      `names` varchar(50) NOT NULL default ''                                COMMENT  '产品名称',
      `type` varchar(20) NOT NULL default ''                                 COMMENT  '产品型号(字符串形式 供应商提供)',
      `acm_code` varchar(30) NOT NULL default ''                             COMMENT 'ACM编号',
      `description` text                                                     COMMENT '产品描述',
      `meterial` varchar(30) default NULL                                    COMMENT '材料',
      `packaging` varchar(30) default NULL                                   COMMENT '包装',
      `qty` smallint(6) default NULL                                         COMMENT '每件多少数量',
      `height` double default NULL                                           COMMENT '高度',
      `width` double default NULL                                            COMMENT '宽度',
      `length` double default NULL                                           COMMENT '长度',
      `cbm` double default NULL                                              COMMENT '体积',
      `gw` double default NULL                                               COMMENT '重量',
      `price_rmb` decimal(8,2) default NULL                                 COMMENT '价格--人民币',
      `price_usd` decimal(8,2) default NULL                                 COMMENT '价格--美元',
      `note` text                                                            COMMENT '公告',
      `picture` varchar(150) default NULL                                    COMMENT '图片',
      `sub` tinyint(1) NOT NULL default '0'                                  COMMENT '是否有子目录的产品',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1                                   COMMENT='产品信息表' AUTO_INCREMENT=1 ;
      

  3.   

    先insert.php简化一下试试:
    <?php
      if(isset($_POST['id'])) echo $_POST['id'];
    ?>
      

  4.   

    @ $db=new mysqli('localhost','root','165832','product');
    ---------------------------------------
    try to change it as :$db=new mysqli('localhost','root','165832','product');or $db = mysqli_connect("localhost", "root", "165832", "product");if (!$db) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
      

  5.   

    问题终于解决了。。
    是@ $db=new mysqli('localhost','root','165832','product');出错。。
    改为@ $db=new mysqli('localhost','root','165832');就可以了。。
    是自己粗心大意
    呵呵