php - 用 php 更新 html 表单
问题描述
我正在尝试使用下面的 php 和 html 代码更新我的 phpmyadmin 数据库:我已成功添加第一行数据,但是一旦我再次尝试使用该表单,我无法添加另一行数据,除非我删除前一个我插入到数据库中。简而言之,我的数据库一次只能有 1 行。谢谢你的帮助 :)
<html>
<head>
</head>
<body>
<form action="inserto.php" method="post">
Customer ID: <input type="number" name="IDc">
<br/>
Stock ID: <input type="number" name="IDs">
<br/>
Date of Purchase: <input type="date" name="dob">
<br/>
Pay status: <input type="text" name="paystatus">
<br/>
Price Paid: <input type="text" name="price">
<br/>
Discount: <input type="text" name="discount">
<br/>
<input type="submit" value="Submit">
</form>
</body>
</html>
<?php
$con = mysqli_connect("localhost", "root", "", "jainam_ia");
if(!$con)
{
echo 'Not connected';
}
$IDc=$_POST['IDc'];
$IDs=$_POST['IDs'];
$dob=$_POST['dob'];
$paystatus=$_POST['paystatus'];
$price=$_POST['price'];
$discount=$_POST['discount'];
$sql = "INSERT INTO tbl_orders (IDc, IDs, Date_of_purchase, Pay_Status, Price_Paid, Discount) VALUES ('$IDc', '$IDs', '$dob', '$paystatus', '$price', '$discount')";
if(!mysqli_query($con,$sql))
{
echo 'Order not added';
}
else
{
echo 'Order added';
}
header("refresh:2; url=indexo.html");
?>
解决方案
很可能在您的 mysql 表tbl_orders
中设置了具有primary_key
属性但没有auto_increment
属性的列。
添加属性示例auto_increment
(您需要将id
名称更改为主键列名称):
ALTER TABLE tbl_orders MODIFY id int AUTO_INCREMENT;
推荐阅读
- java - Google Drive API V3 下载返回 416 错误
- amazon-web-services - 负载均衡器初始请求容量
- javascript - 列表正在更新,但相应的本地存储未更新
- thrift - 异常结束时的 Thrift 消息
- c# - json反序列化为C#中的对象
- java - 如何使用水平滚动条(通过 xpath) - Selenium/Java
- visual-studio-code - 用于运行当前单元格但不将光标移动到 Jupyter for VS Code 中的下一个单元格的键盘快捷键?
- c++ - 为什么我会收到“运行时检查失败 #2 - 围绕变量 'pr' 的堆栈已损坏”错误?
- html -
等在 Swift String - javascript - CSS - 幻灯片文本背景