简体   繁体   English

用php更新html表单

[英]html form updating with php

I am trying to update my phpmyadmin database using the php and html code below: I have been successful in adding a first row of data, but once I try to use the form again I cannot add another row of data unless I delete the previous one I inserted into the database. 我正在尝试使用下面的php和html代码更新我的phpmyadmin数据库:我已经成功添加了第一行数据,但是一旦我再次尝试使用该表单,就无法添加另一行数据,除非我删除了前一行我插入了数据库。 In short, I can only have 1 row in my database at a time. 简而言之,我一次只能在数据库中有1行。 Thanks for any help :) 谢谢你的帮助 :)

<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");

?>

Most likely in your mysql table tbl_orders was set column with primary_key attribute, but without auto_increment attribute. 最有可能在您的mysql表tbl_orders中设置了具有primary_key属性但没有auto_increment属性的列。

Example of adding attribute auto_increment (you need to change id name to your primary key column name): 添加属性auto_increment示例(您需要将id名称更改为您的主键列名称):

ALTER TABLE tbl_orders MODIFY id int AUTO_INCREMENT;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM