我制作了一个在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);
}
答案 0 :(得分:1)
2147483647是mysql中整数的最大值。只需将prod_id
的类型从int更改为bigint。