错误:Champ'product_name'inconnu dans字段列表

时间:2014-06-18 13:35:47

标签: php mysql wampserver

我正在尝试使用WampServer将表单数据存储在数据库中。

当我点击提交按钮时,它会显示以下错误:

"Error: Champ 'product_name' inconnu dans field list".

我正在为另一种形式使用相同的作品。这种形式有效,但我不知道这个有什么问题,请帮帮我

我的表单代码是:

<form action="saddproduct.php" enctype="multipart/form-data" name="myForm" id="myForm" 
 method="post"> 
    <table width="90%" border="1" cellpadding="6">
        <tr>
            <td width="20%">Product Name</td>
            <td width="80%"> 
                <label> 
                <input name="product_name" type="text" id="product_name" size="60" /> 
            </label>    
            </td>
        </tr>
        <tr>
            <td width="20%">Product Code</td>
            <td width="80%"> 
                <label> 
                    <input name="product_code" type="text" id="product_code" size="60" /> 
                </label>    
            </td>
        </tr>
        <tr>
            <td width="20%">Product Availability</td>
            <td width="80%"> 
            <label>
                <select name="availability" id="availability">
                    <option value=""></option>
                    <option value="in"> In Stock </option>
                    <option value="out"> Out Of Stock </option>
                    </select>
                </label>    
            </td>
        </tr>
        <tr>
            <td width="20%">Product Price</td>
            <td width="80%">
            <label>
                Rs.
                <input name="price" type="text" id="price" size="12"  />
            </label>    
            </td>
         </tr>
         <tr>
             <td align="right">Category</td>
            <td>
        <label>
                <select name="category" id="category">
                    <option value=""></option>
                    <option value="living"> Living Rooms </option>
                    <option value="bed"> Bed Rooms </option>
                    <option value="dining"> Dining Rooms </option>
                    </select>
                </label>    
            </td>
        </tr>
        <tr>
            <td align="right">Sub category</td>
            <td>
                <label>
                    <select name="subcategory" id="subcategory">
                        <option value=""></option>
                        <option value="lsofa"> Lining Sofa </option>
                        <option value="lchair"> Living Chair </option>
                        <option value="ltable"> Living Table </option>
                        <option value="bking"> King Beds </option>
                        <option value="bqueen"> Queen Beds </option>
                        <option value="dtable"> Dining Tables </option>
                        <option value="dchairs"> Dining Chairs </option>
                        <option value="hsale"> Sale Item For Home Page </option>
                        <option value="psale"> Sale Item For Sale Page </option>
                    </select>
                </label>
            </td>
        </tr>
        <tr>
            <td width="20%">Product Detail</td>
            <td width="80%">
            <label>
                <textarea name="details" id="details" cols="64" rows="5"> </textarea>
            </label>    
            </td>
        </tr>

        <tr>
            <td>&nbsp;  </td>
            <td width="80%"> 
                <label> 
                    <input type="submit" name="button" id="button" class="button" value="Add This  
         Product Now"  />
                </label>    
            </td>
        </tr>
        <tr>
            <td width="20%">&nbsp;</td>
            <td width="80%">&nbsp;</td>
        </tr>
   </table>
</form>

我处理的PHP页面是saddproduct.php,它看起来像:

<?php
    $con=mysqli_connect("localhost","root","03005225400","furniture");
    // Check connection
    if (mysqli_connect_errno()) {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }


    // escape variables for security
    $product_name = mysqli_real_escape_string($con, $_POST['product_name']);
    $product_code = mysqli_real_escape_string($con, $_POST['product_code']);
    $availability = mysqli_real_escape_string($con, $_POST['availability']);

    $price = mysqli_real_escape_string($con, $_POST['price']);
    $category = mysqli_real_escape_string($con, $_POST['category']);
    $subcategory = mysqli_real_escape_string($con, $_POST['subcategory']);

    $details = mysqli_real_escape_string($con, $_POST['details']);


    $sql="INSERT INTO employee 
              (product_name , product_code, availability, price, 
               category, subcategory, details, date_added) 
          VALUES('$product_name','$product_code', '$availability',     
                '$price','$category','$subcategory','$details',now())" 
          or die (mysql_error());

    if (!mysqli_query($con,$sql)) {
      die('Error: ' . mysqli_error($con));
    }

    mysqli_close($con);
?>

3 个答案:

答案 0 :(得分:4)

我相信如果你验证你的表结构,你将找不到任何名为 product_name 的列,至少不是确切的情况。

尝试验证您的列名称,如果您仍然没有线索,请尝试删除列名称并坚持表格结构的顺序,同时将 NULL 放入具有默认内容(如自动增量)的字段中时间戳。

答案 1 :(得分:0)

简单的拼写错误。表employee应为products

答案 2 :(得分:0)

有时会出现(错误:Champ&#39; Yes&#39; inconnu dans字段列表)类型错误,因为在INSERT查询中使用(`)此单引号而不是使用(&#39;)此引号。 / p>