Mysql PHP插入查询无法正常工作

时间:2014-10-30 14:49:51

标签: php mysql mysqli

我制作了一个在mysql数据库中插入一些信息的脚本。无论我在prod_id字段中输入什么值,'2147483647'都会插入该字段中。正在所有其他字段中正确插入数据。请提出可能导致错误的原因? 以下是相关代码:

<form method="post" name="new_prod" action="new_prod.php">
                <div class="form-group">
                    <input type="text" name="prod_id" class="form-control" placeholder="Enter Product ID" >
                </div>
                <div class="form-group">
                    <input type="text" name="prod_name" class="form-control" placeholder="Enter Product Details" >
                </div>
                <div class="form-group">
                    <input type="text" name="prod_price" class="form-control" placeholder="Enter Product price" >   
                </div>
                <button type="submit" class="btn btn-default" name="sub">Add Product</button>   
            </form>
        </div>
    </div>
</body>
</html>
<?php
$link=mysqli_connect("localhost","root","","smartcart");
if(isset($_POST['sub']))
{
    $prod_id=$_POST['prod_id'];
    $prod_name=$_POST['prod_name'];
    $prod_price=$_POST['prod_price'];
    $a="INSERT into products (prod_id, prod_name, prod_price) VALUES ('$prod_id', '$prod_name', '$prod_price')";
    if (mysqli_query($link,$a))
        {
            echo "Product successfully added to the database";
        }
    else
    {
        $error=mysqli_error($link);
        echo "Product addition failed. Please contact the developer if problem persists.".$error;
    }   
    mysqli_close($link);
}

1 个答案:

答案 0 :(得分:1)

2147483647是mysql中整数的最大值。只需将prod_id的类型从int更改为bigint。